From 6adbfd13266900202f32ec0073b05b38fe2d314e Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Sat, 9 Sep 2017 13:46:09 +0200 Subject: [PATCH 1/2] build: cancel screenshot diff if there is no activity * No longer just gives the screenshot diff task 8 minutes to pass, because the run time can vary. Now it just exits the process if the last action in the task takes longer than 6 minutes. * Instead of just closing the firebase connection, the process will be exited with an error code. Just closing the connection is not helpful and breaks the screenshot diff Web Interface. --- tools/gulp/tasks/screenshots.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/gulp/tasks/screenshots.ts b/tools/gulp/tasks/screenshots.ts index 79aba93f886e..922d11486be2 100644 --- a/tools/gulp/tasks/screenshots.ts +++ b/tools/gulp/tasks/screenshots.ts @@ -34,6 +34,9 @@ const FIREBASE_IMAGE = `${TEMP_FOLDER}/screenshot/images`; const FIREBASE_DATA_GOLDENS = `screenshot/goldens`; const FIREBASE_STORAGE_GOLDENS = 'goldens'; +const lastActionTimeout = 1000 * 60 * 6; +const lastActionRefreshInterval = 1000 * 45; + /** Task which upload screenshots generated from e2e test. */ task('screenshots', () => { const prNumber = process.env['TRAVIS_PULL_REQUEST']; @@ -45,13 +48,18 @@ task('screenshots', () => { const firebaseApp = connectFirebaseScreenshots(); const database = firebaseApp.database(); + let lastActionTime = Date.now(); + // If this task hasn't completed in 8 minutes, close the firebase connection. - const timeoutId = setTimeout(() => { - console.error('Screenshot tests did not finish in 8 minutes, closing Firebase connection.'); - return firebaseApp.delete(); - }, 60 * 1000 * 8); + const timeoutId = setInterval(() => { + if (lastActionTime + lastActionTimeout <= Date.now()) { + clearTimeout(timeoutId); + console.error('Last action for screenshot tests did not finish in ' + + (lastActionTime / 1000 / 60) + ' minutes. Closing Firebase connection...'); + return firebaseApp.delete().then(() => process.exit(1)); + } + }, lastActionRefreshInterval); - let lastActionTime = Date.now(); return uploadTravisJobInfo(database, prNumber) .then(() => { console.log(` Downloading screenshot golds from Firebase...`); From 1f105162c1fd23f103157637ccfe9e05f712d8e1 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 12 Sep 2017 13:42:17 +0200 Subject: [PATCH 2/2] Add comments --- tools/gulp/tasks/screenshots.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/gulp/tasks/screenshots.ts b/tools/gulp/tasks/screenshots.ts index 922d11486be2..e7475fc8d155 100644 --- a/tools/gulp/tasks/screenshots.ts +++ b/tools/gulp/tasks/screenshots.ts @@ -26,15 +26,18 @@ const LOCAL_GOLDENS = path.join(SCREENSHOT_DIR, `golds`); const LOCAL_DIFFS = path.join(SCREENSHOT_DIR, `diff`); // Directory to which untrusted screenshot results are temporarily written -// (without authentication required) before they are verified and copied to -// the final storage location. +// (without authentication required) before they are verified and copied to +// the final storage location. const TEMP_FOLDER = 'untrustedInbox'; const FIREBASE_REPORT = `${TEMP_FOLDER}/screenshot/reports`; const FIREBASE_IMAGE = `${TEMP_FOLDER}/screenshot/images`; const FIREBASE_DATA_GOLDENS = `screenshot/goldens`; const FIREBASE_STORAGE_GOLDENS = 'goldens'; +/** Time in ms until the process will be exited if the last action took too long (6 minutes). */ const lastActionTimeout = 1000 * 60 * 6; + +/** Time in ms that specifies how often the last action should be checked (45 seconds). */ const lastActionRefreshInterval = 1000 * 45; /** Task which upload screenshots generated from e2e test. */ @@ -47,19 +50,20 @@ task('screenshots', () => { } else if (prNumber) { const firebaseApp = connectFirebaseScreenshots(); const database = firebaseApp.database(); - let lastActionTime = Date.now(); - // If this task hasn't completed in 8 minutes, close the firebase connection. + // If the last action of the task takes longer than 6 minutes, close the firebase connection. const timeoutId = setInterval(() => { if (lastActionTime + lastActionTimeout <= Date.now()) { clearTimeout(timeoutId); console.error('Last action for screenshot tests did not finish in ' + - (lastActionTime / 1000 / 60) + ' minutes. Closing Firebase connection...'); + (lastActionTimeout / 1000 / 60) + ' minutes. Closing Firebase connection...'); return firebaseApp.delete().then(() => process.exit(1)); } }, lastActionRefreshInterval); + console.log(` Starting screenshots task with results from e2e task...`); + return uploadTravisJobInfo(database, prNumber) .then(() => { console.log(` Downloading screenshot golds from Firebase...`);