@@ -21,10 +21,9 @@ import { resolve } from 'path';
2121import Fs from 'fs' ;
2222
2323import * as Rx from 'rxjs' ;
24- import { mergeMap , map , takeUntil } from 'rxjs/operators' ;
24+ import { mergeMap , map , takeUntil , catchError } from 'rxjs/operators' ;
2525import { Lifecycle } from '@kbn/test/src/functional_test_runner/lib/lifecycle' ;
2626import { ToolingLog } from '@kbn/dev-utils' ;
27- import { delay } from 'bluebird' ;
2827import chromeDriver from 'chromedriver' ;
2928// @ts -ignore types not available
3029import 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