diff --git a/test/hooks_functional.js b/test/hooks_functional.js index 7a02322442..4b8e335822 100644 --- a/test/hooks_functional.js +++ b/test/hooks_functional.js @@ -16,7 +16,7 @@ import events from 'events'; events.EventEmitter.prototype._maxListeners = 100; -const timeout = 50000; +const TIMEOUT = 50000; let itownsServer; let itownsPort; @@ -82,11 +82,14 @@ function waitServerReady(port) { }); } -const layersInitialization = async (forceTimeOut = false) => { - await page.waitForFunction(forceTimeOut => (view.mainLoop.scheduler.commandsWaitingExecutionCount() === 0 +const initializeLayers = async (timeout = TIMEOUT) => { + await page.waitForFunction( + () => (view.mainLoop.scheduler.commandsWaitingExecutionCount() === 0 && view.mainLoop.renderingState === 0 - && view.getLayers().every(layer => layer.ready) - && !forceTimeOut), { timeout }, forceTimeOut); + && view.getLayers().every(layer => layer.ready)), + { timeout }, + timeout, + ); }; const waitNextRender = async page => page.evaluate(() => new Promise((resolve) => { @@ -135,19 +138,14 @@ const loadExample = async (url, screenshotName) => { }); try { - await layersInitialization(); + await initializeLayers(); } catch (e) { if (e instanceof Error && e.name === 'TimeoutError') { - console.warn(' *** Warning: layersInitialization timed out -> it got stopped ***'); + console.warn(' *** Warning: initializeLayers timed out -> Camera motion had been stopped ***'); await page.evaluate(() => { itowns.CameraUtils.stop(view, view.camera3D); }); - try { - await layersInitialization(); - } catch (e) { - console.warn(e); - throw e; - } + await initializeLayers(); } else { console.warn(e); throw e;