Skip to content

Commit 7ca74ea

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>
1 parent 63c704e commit 7ca74ea

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 { 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';
@@ -327,25 +326,33 @@ export async function initWebDriver(
327326
edgePaths = await installDriver();
328327
}
329328

330-
return await Promise.race([
331-
(async () => {
332-
await delay(2 * MINUTE);
333-
throw new Error('remote failed to start within 2 minutes');
334-
})(),
335-
336-
(async () => {
337-
while (true) {
338-
const command = await Promise.race([
339-
delay(30 * SECOND),
340-
attemptToCreateCommand(log, browserType, lifecycle, config),
341-
]);
329+
return await Rx.race(
330+
Rx.timer(2 * MINUTE).pipe(
331+
map(() => {
332+
throw new Error('remote failed to start within 2 minutes');
333+
})
334+
),
342335

336+
Rx.race(
337+
Rx.defer(async () => {
338+
const command = await attemptToCreateCommand(log, browserType, lifecycle, config);
343339
if (!command) {
344-
continue;
340+
throw new Error('remote creation aborted');
345341
}
346-
347342
return command;
348-
}
349-
})(),
350-
]);
343+
}),
344+
Rx.timer(30 * SECOND).pipe(
345+
map(() => {
346+
throw new Error('remote failed to start within 30 seconds');
347+
})
348+
)
349+
).pipe(
350+
catchError((error, resubscribe) => {
351+
log.warning('Failure while creating webdriver instance');
352+
log.warning(error);
353+
log.warning('...retrying...');
354+
return resubscribe;
355+
})
356+
)
357+
).toPromise();
351358
}

0 commit comments

Comments
 (0)