Skip to content

Commit 34b5620

Browse files
devversionmmalerba
authored andcommitted
build: cancel screenshot diff if there is no activity (#6957)
* 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. * Add comments
1 parent b8218e1 commit 34b5620

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

tools/gulp/tasks/screenshots.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,20 @@ const LOCAL_GOLDENS = path.join(SCREENSHOT_DIR, `golds`);
2626
const LOCAL_DIFFS = path.join(SCREENSHOT_DIR, `diff`);
2727

2828
// Directory to which untrusted screenshot results are temporarily written
29-
// (without authentication required) before they are verified and copied to
30-
// the final storage location.
29+
// (without authentication required) before they are verified and copied to
30+
// the final storage location.
3131
const TEMP_FOLDER = 'untrustedInbox';
3232
const FIREBASE_REPORT = `${TEMP_FOLDER}/screenshot/reports`;
3333
const FIREBASE_IMAGE = `${TEMP_FOLDER}/screenshot/images`;
3434
const FIREBASE_DATA_GOLDENS = `screenshot/goldens`;
3535
const FIREBASE_STORAGE_GOLDENS = 'goldens';
3636

37+
/** Time in ms until the process will be exited if the last action took too long (6 minutes). */
38+
const lastActionTimeout = 1000 * 60 * 6;
39+
40+
/** Time in ms that specifies how often the last action should be checked (45 seconds). */
41+
const lastActionRefreshInterval = 1000 * 45;
42+
3743
/** Task which upload screenshots generated from e2e test. */
3844
task('screenshots', () => {
3945
const prNumber = process.env['TRAVIS_PULL_REQUEST'];
@@ -44,14 +50,20 @@ task('screenshots', () => {
4450
} else if (prNumber) {
4551
const firebaseApp = connectFirebaseScreenshots();
4652
const database = firebaseApp.database();
53+
let lastActionTime = Date.now();
4754

48-
// If this task hasn't completed in 8 minutes, close the firebase connection.
49-
const timeoutId = setTimeout(() => {
50-
console.error('Screenshot tests did not finish in 8 minutes, closing Firebase connection.');
51-
return firebaseApp.delete();
52-
}, 60 * 1000 * 8);
55+
// If the last action of the task takes longer than 6 minutes, close the firebase connection.
56+
const timeoutId = setInterval(() => {
57+
if (lastActionTime + lastActionTimeout <= Date.now()) {
58+
clearTimeout(timeoutId);
59+
console.error('Last action for screenshot tests did not finish in ' +
60+
(lastActionTimeout / 1000 / 60) + ' minutes. Closing Firebase connection...');
61+
return firebaseApp.delete().then(() => process.exit(1));
62+
}
63+
}, lastActionRefreshInterval);
64+
65+
console.log(` Starting screenshots task with results from e2e task...`);
5366

54-
let lastActionTime = Date.now();
5567
return uploadTravisJobInfo(database, prNumber)
5668
.then(() => {
5769
console.log(` Downloading screenshot golds from Firebase...`);

0 commit comments

Comments
 (0)