Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
[ftr/webdriver] retry on all errors, use Rx so that timers are cancel…
Browse files Browse the repository at this point in the history
…ed (elastic#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>
  • Loading branch information
Spencer and spalger committed Jul 21, 2020
1 parent 63c704e commit 7ca74ea
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions test/functional/services/remote/webdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import { resolve } from 'path';
import Fs from 'fs';

import * as Rx from 'rxjs';
import { mergeMap, map, takeUntil } from 'rxjs/operators';
import { mergeMap, map, takeUntil, catchError } from 'rxjs/operators';
import { Lifecycle } from '@kbn/test/src/functional_test_runner/lib/lifecycle';
import { ToolingLog } from '@kbn/dev-utils';
import { delay } from 'bluebird';
import chromeDriver from 'chromedriver';
// @ts-ignore types not available
import geckoDriver from 'geckodriver';
Expand Down Expand Up @@ -327,25 +326,33 @@ export async function initWebDriver(
edgePaths = await installDriver();
}

return await Promise.race([
(async () => {
await delay(2 * MINUTE);
throw new Error('remote failed to start within 2 minutes');
})(),

(async () => {
while (true) {
const command = await Promise.race([
delay(30 * SECOND),
attemptToCreateCommand(log, browserType, lifecycle, config),
]);
return await Rx.race(
Rx.timer(2 * MINUTE).pipe(
map(() => {
throw new Error('remote failed to start within 2 minutes');
})
),

Rx.race(
Rx.defer(async () => {
const command = await attemptToCreateCommand(log, browserType, lifecycle, config);
if (!command) {
continue;
throw new Error('remote creation aborted');
}

return command;
}
})(),
]);
}),
Rx.timer(30 * SECOND).pipe(
map(() => {
throw new Error('remote failed to start within 30 seconds');
})
)
).pipe(
catchError((error, resubscribe) => {
log.warning('Failure while creating webdriver instance');
log.warning(error);
log.warning('...retrying...');
return resubscribe;
})
)
).toPromise();
}

0 comments on commit 7ca74ea

Please sign in to comment.