@@ -38,11 +38,8 @@ import { handleSessionObservabilityCommands } from './session-observability.ts';
3838import { handleSessionReplayCommands } from './session-replay.ts' ;
3939import { getSessionCommandKind } from '../daemon-command-registry.ts' ;
4040import { LeaseRegistry } from '../lease-registry.ts' ;
41-
42- const PREPARE_IOS_RUNNER_MIN_STARTUP_TIMEOUT_MS = 45_000 ;
43- const PREPARE_IOS_RUNNER_DEFAULT_BUILD_TIMEOUT_MS = 5 * 60_000 ;
44- const PREPARE_IOS_RUNNER_HEALTH_TIMEOUT_MS = 90_000 ;
45- const PREPARE_IOS_RUNNER_MAX_HEALTH_TIMEOUT_MS = 3 * 60_000 ;
41+ import { PREPARE_REQUEST_TIMEOUT_MS } from '../request-timeouts.ts' ;
42+ import { Deadline } from '../../utils/retry.ts' ;
4643
4744async function handlePrepareCommand ( params : {
4845 req : DaemonRequest ;
@@ -76,7 +73,7 @@ async function handlePrepareCommand(params: {
7673 const startedAtMs = Date . now ( ) ;
7774 const result = await prepareIosRunner (
7875 device ,
79- buildPrepareIosRunnerOptions ( req , session , logPath ) ,
76+ buildPrepareIosRunnerOptions ( req , session , logPath , startedAtMs ) ,
8077 ) ;
8178 const durationMs = Math . max ( 0 , Date . now ( ) - startedAtMs ) ;
8279 return {
@@ -89,51 +86,28 @@ function buildPrepareIosRunnerOptions(
8986 req : DaemonRequest ,
9087 session : SessionState | undefined ,
9188 logPath : string ,
89+ startedAtMs : number ,
9290) : Parameters < typeof prepareIosRunner > [ 1 ] {
93- const buildTimeoutMs = readPrepareIosRunnerBuildTimeoutMs ( req ) ;
91+ const timeoutMs = readPrepareIosRunnerTimeoutMs ( req ) ;
9492 return {
9593 ...buildAppleRunnerRequestOptions ( {
9694 req,
9795 logPath,
9896 traceLogPath : session ?. trace ?. outPath ,
9997 } ) ,
10098 cleanStaleBundles : true ,
101- startupTimeoutMs : resolvePrepareIosRunnerStartupTimeoutMs ( req . flags ?. timeoutMs ) ,
102- buildTimeoutMs,
103- healthTimeoutMs : resolvePrepareIosRunnerHealthTimeoutMs ( req . flags ?. timeoutMs , buildTimeoutMs ) ,
99+ buildTimeoutMs : timeoutMs ,
100+ healthTimeoutMs : timeoutMs ,
101+ prepareDeadline : Deadline . fromTimeoutMs ( timeoutMs , startedAtMs ) ,
102+ startupTimeoutMs : timeoutMs ,
104103 } ;
105104}
106105
107- function resolvePrepareIosRunnerStartupTimeoutMs ( timeoutMs : unknown ) : number | undefined {
108- if ( typeof timeoutMs !== 'number' || ! Number . isFinite ( timeoutMs ) || timeoutMs <= 0 ) {
109- return undefined ;
110- }
111- return Math . max ( PREPARE_IOS_RUNNER_MIN_STARTUP_TIMEOUT_MS , Math . floor ( timeoutMs ) ) ;
112- }
113-
114- function readPrepareIosRunnerBuildTimeoutMs ( req : DaemonRequest ) : number {
106+ function readPrepareIosRunnerTimeoutMs ( req : DaemonRequest ) : number {
115107 const value = req . flags ?. timeoutMs ;
116108 return typeof value === 'number' && Number . isFinite ( value ) && value > 0
117109 ? value
118- : PREPARE_IOS_RUNNER_DEFAULT_BUILD_TIMEOUT_MS ;
119- }
120-
121- function resolvePrepareIosRunnerHealthTimeoutMs (
122- timeoutMs : unknown ,
123- buildTimeoutMs : number ,
124- ) : number {
125- const configuredTimeout =
126- typeof timeoutMs === 'number' && Number . isFinite ( timeoutMs ) && timeoutMs > 0
127- ? Math . floor ( timeoutMs )
128- : undefined ;
129- if ( ! configuredTimeout ) {
130- return Math . min ( buildTimeoutMs , PREPARE_IOS_RUNNER_HEALTH_TIMEOUT_MS ) ;
131- }
132- return Math . min (
133- buildTimeoutMs ,
134- PREPARE_IOS_RUNNER_MAX_HEALTH_TIMEOUT_MS ,
135- Math . max ( PREPARE_IOS_RUNNER_HEALTH_TIMEOUT_MS , Math . floor ( configuredTimeout / 2 ) ) ,
136- ) ;
110+ : PREPARE_REQUEST_TIMEOUT_MS ;
137111}
138112
139113function prepareIosRunnerResponseData (
0 commit comments