2015-07-23 19:02:16 +00:00
|
|
|
/* jslint node:true */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('supererror')({ splatchError: true });
|
|
|
|
|
2015-07-24 00:03:26 +00:00
|
|
|
var debug = require('debug')('e2e:runner'),
|
2015-07-23 19:02:16 +00:00
|
|
|
mailer = require('./mailer.js'),
|
2016-09-14 14:19:23 +00:00
|
|
|
mkdirp = require('mkdirp'),
|
2016-09-21 17:39:09 +00:00
|
|
|
path = require('path'),
|
2016-09-14 14:19:23 +00:00
|
|
|
rimraf = require('rimraf'),
|
2016-09-21 17:39:09 +00:00
|
|
|
semver = require('semver'),
|
|
|
|
shell = require('./shell.js'),
|
2015-07-23 19:02:16 +00:00
|
|
|
superagent = require('superagent'),
|
2015-07-25 01:27:03 +00:00
|
|
|
terminate = require('terminate'),
|
2015-07-28 01:12:26 +00:00
|
|
|
util = require('util'),
|
|
|
|
_ = require('underscore');
|
2015-07-23 19:02:16 +00:00
|
|
|
|
|
|
|
// override debug.log to print only as console.log
|
|
|
|
debug.log = console.log.bind(console);
|
|
|
|
|
2015-07-28 01:12:26 +00:00
|
|
|
var gLatestVersionInfo = null; // do not use etag since it only hashes body. do not use s3 filestamp since the upgrade test modifies it....
|
2015-07-25 01:27:03 +00:00
|
|
|
var gNpmTest = null;
|
|
|
|
|
|
|
|
function cleanExit() {
|
|
|
|
if (gNpmTest) {
|
|
|
|
debug('Terminating child test process %s', gNpmTest.pid);
|
|
|
|
terminate(gNpmTest.pid, process.exit);
|
|
|
|
gNpmTest = null;
|
|
|
|
} else {
|
|
|
|
debug('No child test process to terminate');
|
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
}
|
2015-07-23 19:02:16 +00:00
|
|
|
|
|
|
|
function start() {
|
2015-07-25 01:27:03 +00:00
|
|
|
setTimeout(runTestsIfNeeded.bind(null, start), 60 * 1000);
|
2015-07-23 19:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function runTestsIfNeeded(callback) {
|
|
|
|
debug('Getting latest box version');
|
|
|
|
|
2015-07-28 01:12:26 +00:00
|
|
|
getLatestBoxVersion(function (error, latestVersionInfo) {
|
2015-07-23 19:02:16 +00:00
|
|
|
if (error) return callback(error);
|
|
|
|
|
2015-07-28 01:12:26 +00:00
|
|
|
if (_.isEqual(gLatestVersionInfo, latestVersionInfo)) {
|
|
|
|
debug('Box version has not changed');
|
2015-07-23 21:10:21 +00:00
|
|
|
return callback();
|
2015-07-23 19:02:16 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 01:12:26 +00:00
|
|
|
debug('Box version has changed. latestVersionInfo:%j', latestVersionInfo);
|
2015-07-23 21:10:21 +00:00
|
|
|
|
2015-07-28 01:12:26 +00:00
|
|
|
var diff = (new Date() - new Date(latestVersionInfo.date));
|
2016-12-30 23:30:40 +00:00
|
|
|
if (diff < 5 * 60 * 1000) { // give appstore 5 mins
|
2015-07-23 21:10:21 +00:00
|
|
|
debug('Waiting for appstore gets the new release. diff=%s', diff);
|
|
|
|
return callback();
|
|
|
|
}
|
2015-07-23 19:02:16 +00:00
|
|
|
|
2015-07-28 01:12:26 +00:00
|
|
|
runTests(latestVersionInfo, function (error) {
|
|
|
|
debug('Finished running tests for %j %s', latestVersionInfo, error);
|
|
|
|
gLatestVersionInfo = latestVersionInfo;
|
2015-07-23 19:02:16 +00:00
|
|
|
callback(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLatestBoxVersion(callback) {
|
|
|
|
superagent.get(process.env.BOX_VERSIONS_URL).end(function (error, res) {
|
|
|
|
if (error || res.statusCode !== 200 || !res.body) {
|
2015-07-23 19:45:26 +00:00
|
|
|
debug('Error downloading versions file', error || res.statusCode);
|
2015-07-23 19:02:16 +00:00
|
|
|
return callback(new Error('Error downloading versions file'));
|
|
|
|
}
|
|
|
|
|
2015-07-28 01:12:26 +00:00
|
|
|
var latestVersionInfo = Object.keys(res.body).sort(semver.rcompare)[0];
|
2015-07-23 19:02:16 +00:00
|
|
|
|
2015-07-28 01:12:26 +00:00
|
|
|
var result = _.extend({ }, res.body[latestVersionInfo]);
|
|
|
|
result.version = latestVersionInfo;
|
2015-07-23 19:02:16 +00:00
|
|
|
|
2015-07-28 01:12:26 +00:00
|
|
|
callback(null, result);
|
2015-07-23 19:02:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-07-28 01:12:26 +00:00
|
|
|
function runTests(latestVersionInfo, callback) {
|
|
|
|
debug('Running tests for %j', latestVersionInfo);
|
2015-07-23 19:02:16 +00:00
|
|
|
|
2016-09-21 17:39:09 +00:00
|
|
|
gNpmTest = shell.system('e2etestrunner', 'BOX_VERSION=' + latestVersionInfo.version + ' npm run-script parallel_test', function (error, stdout, stderr) {
|
2015-07-25 01:27:03 +00:00
|
|
|
gNpmTest = null;
|
2015-07-23 19:56:35 +00:00
|
|
|
debug('Final test result', error);
|
2015-07-23 19:02:16 +00:00
|
|
|
|
2015-07-28 01:35:09 +00:00
|
|
|
var topic = util.format('E2E Test %s for box version: %s', error ? 'failed': 'passed', latestVersionInfo.version);
|
2015-07-28 01:12:26 +00:00
|
|
|
|
2015-11-19 21:49:13 +00:00
|
|
|
// do not send stderr in mail since it contains the tail log stream
|
2016-09-21 20:33:19 +00:00
|
|
|
mailer.sendEndToEndTestResult(topic, JSON.stringify(latestVersionInfo, null, 4), stdout ? stdout.toString('utf8') : '', '', path.resolve(path.join(__dirname, 'logs')), function (error) { if (error) console.log(error); });
|
2015-07-23 19:56:35 +00:00
|
|
|
return callback(error);
|
2015-07-23 19:02:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('e2etest started.');
|
2015-07-25 01:27:03 +00:00
|
|
|
|
|
|
|
process.on('exit', cleanExit);
|
|
|
|
process.on('SIGINT', cleanExit); // catch ctrl-c
|
|
|
|
process.on('SIGTERM', cleanExit); // catch kill
|
|
|
|
process.on('uncaughtException', cleanExit);
|
|
|
|
|
2015-07-23 19:02:16 +00:00
|
|
|
start();
|