Skip to content

Commit e8b4467

Browse files
Spencerspalger
andcommitted
[ftr/webdriver] retry on all errors, use Rx so that timers are canceled (#72540)
* [ftr/webdriver] retry on all errors, use Rx so that timers are canceled * throw if attemptToCreateCommand() aborts by resolving to undefined Co-authored-by: spalger <spalger@users.noreply.github.com> # Conflicts: # test/functional/services/remote/webdriver.ts
1 parent 4fd8c79 commit e8b4467

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

test/functional/services/remote/webdriver.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ import { delimiter, resolve } from 'path';
2121
import Fs from 'fs';
2222

2323
import * as Rx from 'rxjs';
24-
import { mergeMap, map, takeUntil } from 'rxjs/operators';
24+
import { mergeMap, map, takeUntil, catchError } from 'rxjs/operators';
2525
import { Lifecycle } from '@kbn/test/src/functional_test_runner/lib/lifecycle';
2626
import { ToolingLog } from '@kbn/dev-utils';
27-
import { delay } from 'bluebird';
2827
import chromeDriver from 'chromedriver';
2928
// @ts-ignore types not available
3029
import geckoDriver from 'geckodriver';
@@ -353,25 +352,33 @@ export async function initWebDriver(
353352
edgePaths = await installDriver();
354353
}
355354

356-
return await Promise.race([
357-
(async () => {
358-
await delay(2 * MINUTE);
359-
throw new Error('remote failed to start within 2 minutes');
360-
})(),
361-
362-
(async () => {
363-
while (true) {
364-
const command = await Promise.race([
365-
delay(30 * SECOND),
366-
attemptToCreateCommand(log, browserType, lifecycle, logPollingMs),
367-
]);
355+
return await Rx.race(
356+
Rx.timer(2 * MINUTE).pipe(
357+
map(() => {
358+
throw new Error('remote failed to start within 2 minutes');
359+
})
360+
),
368361

362+
Rx.race(
363+
Rx.defer(async () => {
364+
const command = await attemptToCreateCommand(log, browserType, lifecycle, logPollingMs);
369365
if (!command) {
370-
continue;
366+
throw new Error('remote creation aborted');
371367
}
372-
373368
return command;
374-
}
375-
})(),
376-
]);
369+
}),
370+
Rx.timer(30 * SECOND).pipe(
371+
map(() => {
372+
throw new Error('remote failed to start within 30 seconds');
373+
})
374+
)
375+
).pipe(
376+
catchError((error, resubscribe) => {
377+
log.warning('Failure while creating webdriver instance');
378+
log.warning(error);
379+
log.warning('...retrying...');
380+
return resubscribe;
381+
})
382+
)
383+
).toPromise();
377384
}

0 commit comments

Comments
 (0)