File tree Expand file tree Collapse file tree 8 files changed +20
-19
lines changed
packages/respect-core/src Expand file tree Collapse file tree 8 files changed +20
-19
lines changed Original file line number Diff line number Diff line change 1- export const RESPECT_TIMEOUT = 3600000 ; // 1 hour in milliseconds
2- export const MAX_FETCH_TIMEOUT = 20000 ; // 20 seconds in milliseconds
1+ export const DEFAULT_RESPECT_TIMEOUT = 3600000 ; // 1 hour in milliseconds
2+ export const DEFAULT_MAX_FETCH_TIMEOUT = 20000 ; // 20 seconds in milliseconds
Original file line number Diff line number Diff line change @@ -12,8 +12,9 @@ import { DefaultLogger } from '../utils/logger/logger';
1212import { exitWithError } from '../utils/exit-with-error' ;
1313import { writeFileSync } from 'node:fs' ;
1414import { indent } from '../utils/cli-outputs' ;
15- import { Timer } from '../modules/timeout-timer' ;
16- import { type JsonLogs , type CommandArgs , type RunArgv } from '../types' ;
15+ import { Timer } from '../modules/timeout-timer/timer' ;
16+
17+ import type { JsonLogs , CommandArgs , RunArgv } from '../types' ;
1718
1819export type RespectOptions = {
1920 files : string [ ] ;
Original file line number Diff line number Diff line change @@ -3990,7 +3990,9 @@ describe('runStep', () => {
39903990 const mockTimer = {
39913991 isTimedOut : jest . fn ( ) . mockReturnValue ( true ) ,
39923992 } ;
3993- jest . spyOn ( require ( '../../timeout-timer' ) . Timer , 'getInstance' ) . mockReturnValue ( mockTimer ) ;
3993+ jest
3994+ . spyOn ( require ( '../../timeout-timer/timer' ) . Timer , 'getInstance' )
3995+ . mockReturnValue ( mockTimer ) ;
39943996
39953997 const checks : Check [ ] = [ ] ;
39963998 const step = {
Original file line number Diff line number Diff line change @@ -48,14 +48,14 @@ export function displayErrors(workflows: WorkflowExecutionResult[]) {
4848
4949 for ( const failedCheckIndex in failedStepChecks ) {
5050 const { name, message, severity } = failedStepChecks [ failedCheckIndex ] ;
51- const showErrorMessage = ! [
51+ const showRespectInnerErrorMessage = [
5252 CHECKS . UNEXPECTED_ERROR ,
5353 CHECKS . GLOBAL_TIMEOUT_ERROR ,
5454 CHECKS . MAX_STEPS_REACHED_ERROR ,
5555 ] . includes ( name ) ;
56- const messageToDisplay = showErrorMessage
57- ? indent ( `${ removeExtraIndentation ( message ) } ${ RESET_ESCAPE_CODE } \n ` , 6 )
58- : indent ( `Reason: ${ message } ` , 4 ) ;
56+ const messageToDisplay = showRespectInnerErrorMessage
57+ ? indent ( `Reason: ${ message } ` , 4 )
58+ : indent ( `${ removeExtraIndentation ( message ) } ${ RESET_ESCAPE_CODE } \n ` , 6 ) ;
5959
6060 logger . printNewLine ( ) ;
6161
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import {
1818} from '../config-parser' ;
1919import { evaluateRuntimeExpressionPayload } from '../runtime-expressions' ;
2020import { DefaultLogger } from '../../utils/logger/logger' ;
21- import { Timer } from '../timeout-timer' ;
21+ import { Timer } from '../timeout-timer/timer ' ;
2222
2323import type {
2424 Check ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- import { RESPECT_TIMEOUT } from '../../consts' ;
1+ import { DEFAULT_RESPECT_TIMEOUT } from '../../consts' ;
22
33export class Timer {
44 private static instance : Timer ;
@@ -16,10 +16,9 @@ export class Timer {
1616 }
1717
1818 public isTimedOut ( ) : boolean {
19- const elapsedTime = Date . now ( ) - this . startTime ;
20- const timeout = parseInt ( process . env . RESPECT_TIMEOUT || RESPECT_TIMEOUT . toString ( ) , 10 ) ;
21- const remainingTime = Math . max ( 0 , timeout - elapsedTime ) ;
22-
23- return remainingTime <= 0 ;
19+ const timeout = isNaN ( + ( process . env . RESPECT_TIMEOUT as string ) )
20+ ? DEFAULT_RESPECT_TIMEOUT
21+ : + ( process . env . RESPECT_TIMEOUT as string ) ;
22+ return Date . now ( ) - this . startTime > timeout ;
2423 }
2524}
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import { getResponseSchema } from '../modules/description-parser';
1717import { collectSecretFields } from '../modules/flow-runner' ;
1818import { createMtlsClient } from './mtls/create-mtls-client' ;
1919import { DefaultLogger } from './logger/logger' ;
20- import { MAX_FETCH_TIMEOUT } from '../consts' ;
20+ import { DEFAULT_MAX_FETCH_TIMEOUT } from '../consts' ;
2121
2222import type { RequestData } from '../modules/flow-runner' ;
2323
@@ -239,7 +239,7 @@ export class ApiFetcher implements IFetcher {
239239 body : encodedBody ,
240240 } ) ,
241241 redirect : 'follow' ,
242- signal : AbortSignal . timeout ( MAX_FETCH_TIMEOUT ) ,
242+ signal : AbortSignal . timeout ( DEFAULT_MAX_FETCH_TIMEOUT ) ,
243243 // Required for application/octet-stream content type requests
244244 ...( headers [ 'content-type' ] === 'application/octet-stream' && {
245245 duplex : 'half' ,
You can’t perform that action at this time.
0 commit comments