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
This commit is contained in:
Paul Gschwendtner
2017-09-15 02:11:12 +02:00
committed by mmalerba
parent b8218e1489
commit 34b5620aa3
+21 -9
View File
@@ -26,14 +26,20 @@ 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. */
task('screenshots', () => {
const prNumber = process.env['TRAVIS_PULL_REQUEST'];
@@ -44,14 +50,20 @@ task('screenshots', () => {
} else if (prNumber) {
const firebaseApp = connectFirebaseScreenshots();
const database = firebaseApp.database();
// 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);
let lastActionTime = Date.now();
// 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 ' +
(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...`);