Compare version info instead of timestamp

timestamp approach does not work because the update test modifies the
version info file
This commit is contained in:
Girish Ramakrishnan 2015-07-27 18:12:26 -07:00
parent 764f0bc9ca
commit 154cc9eb4f
3 changed files with 25 additions and 24 deletions

View File

@ -10,12 +10,13 @@ var debug = require('debug')('e2e:runner'),
mailer = require('./mailer.js'), mailer = require('./mailer.js'),
superagent = require('superagent'), superagent = require('superagent'),
terminate = require('terminate'), terminate = require('terminate'),
util = require('util'); util = require('util'),
_ = require('underscore');
// override debug.log to print only as console.log // override debug.log to print only as console.log
debug.log = console.log.bind(console); debug.log = console.log.bind(console);
var gLastModified = null; // do not use etag since it only hashes body. touching file to rerun tests is nice var gLatestVersionInfo = null; // do not use etag since it only hashes body. do not use s3 filestamp since the upgrade test modifies it....
var gNpmTest = null; var gNpmTest = null;
function cleanExit() { function cleanExit() {
@ -36,25 +37,25 @@ function start() {
function runTestsIfNeeded(callback) { function runTestsIfNeeded(callback) {
debug('Getting latest box version'); debug('Getting latest box version');
getLatestBoxVersion(function (error, latestETag, latestBoxVersion, lastModified) { getLatestBoxVersion(function (error, latestVersionInfo) {
if (error) return callback(error); if (error) return callback(error);
if (lastModified === gLastModified) { if (_.isEqual(gLatestVersionInfo, latestVersionInfo)) {
debug('Box version has not changed. etag:%s lm:%s', latestETag, lastModified); debug('Box version has not changed');
return callback(); return callback();
} }
debug('Box version has changed. etag %s lm:%s', latestETag, lastModified); debug('Box version has changed. latestVersionInfo:%j', latestVersionInfo);
var diff = (new Date() - lastModified); var diff = (new Date() - new Date(latestVersionInfo.date));
if (diff < 3 * 60 * 1000) { // give appstore 3 mins if (diff < 3 * 60 * 1000) { // give appstore 3 mins
debug('Waiting for appstore gets the new release. diff=%s', diff); debug('Waiting for appstore gets the new release. diff=%s', diff);
return callback(); return callback();
} }
runTests(latestETag, latestBoxVersion, lastModified, function (error) { runTests(latestVersionInfo, function (error) {
debug('Finished running tests for etag %s / lm %s: %s', latestETag, lastModified, error); debug('Finished running tests for %j %s', latestVersionInfo, error);
gLastModified = lastModified; gLatestVersionInfo = latestVersionInfo;
callback(error); callback(error);
}); });
}); });
@ -67,26 +68,25 @@ function getLatestBoxVersion(callback) {
return callback(new Error('Error downloading versions file')); return callback(new Error('Error downloading versions file'));
} }
var latestVersion = Object.keys(res.body).sort(semver.rcompare)[0]; var latestVersionInfo = Object.keys(res.body).sort(semver.rcompare)[0];
var latestETag = res.headers['etag'];
var lastModified = new Date(res.headers['last-modified']);
debug('%j:', res.headers); var result = _.extend({ }, res.body[latestVersionInfo]);
result.version = latestVersionInfo;
callback(null, latestETag, latestVersion, lastModified); callback(null, result);
}); });
} }
function runTests(latestETag, latestBoxVersion, lastModified, callback) { function runTests(latestVersionInfo, callback) {
var topic = util.format('box version: %s etag: %s lastModified:%s', latestBoxVersion, latestETag, lastModified); debug('Running tests for %j', latestVersionInfo);
debug('Running tests for %s', topic);
gNpmTest = shell.system('e2etestrunner', 'npm test', function (error, stdout, stderr) { gNpmTest = shell.system('e2etestrunner', 'npm test', function (error, stdout, stderr) {
gNpmTest = null; gNpmTest = null;
debug('Final test result', error); debug('Final test result', error);
mailer.sendEndToEndTestResult(topic, stdout ? stdout.toString('utf8') : '', stderr ? stderr.toString('utf8') : '', function () { }); var topic = util.format('E2E Test %s for box version: %s', error ? 'failed': 'succeess', latestVersionInfo.version);
mailer.sendEndToEndTestResult(topic, JSON.stringify(latestVersionInfo, null, 4), stdout ? stdout.toString('utf8') : '', stderr ? stderr.toString('utf8') : '', function () { });
return callback(error); return callback(error);
}); });
} }

View File

@ -37,13 +37,13 @@ function send(options, callback) {
}); });
} }
function sendEndToEndTestResult(topic, stdout, stderr, callback) { function sendEndToEndTestResult(topic, versionInfo, stdout, stderr, callback) {
debug('Sending e2e test result for %s', topic); debug('Sending e2e test result for %s', topic);
var mailOptions = { var mailOptions = {
to: 'admin@cloudron.io', to: 'admin@cloudron.io',
subject: util.format('E2E test results for box %s', topic), subject: util.format('E2E test results for %s', topic),
text: 'stdout\n------\n' + stdout.toString('utf8') + '\n\nstderr\n------\n' + stderr.toString('utf8') + '\n\n' text: versionInfo + '\n\nstdout\n------\n' + stdout.toString('utf8') + '\n\nstderr\n------\n' + stderr.toString('utf8') + '\n\n'
}; };
send(mailOptions, callback); send(mailOptions, callback);

View File

@ -31,6 +31,7 @@
"superagent": "^1.2.0", "superagent": "^1.2.0",
"superagent-sync": "^0.1.0", "superagent-sync": "^0.1.0",
"supererror": "^0.7.0", "supererror": "^0.7.0",
"terminate": "^1.0.5" "terminate": "^1.0.5",
"underscore": "^1.8.3"
} }
} }