From 154cc9eb4fd9de805e82ebc13276e2ccaf66a724 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Mon, 27 Jul 2015 18:12:26 -0700 Subject: [PATCH] Compare version info instead of timestamp timestamp approach does not work because the update test modifies the version info file --- e2etestrunner.js | 40 ++++++++++++++++++++-------------------- mailer.js | 6 +++--- package.json | 3 ++- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/e2etestrunner.js b/e2etestrunner.js index 08b6d31..d320d66 100755 --- a/e2etestrunner.js +++ b/e2etestrunner.js @@ -10,12 +10,13 @@ var debug = require('debug')('e2e:runner'), mailer = require('./mailer.js'), superagent = require('superagent'), terminate = require('terminate'), - util = require('util'); + util = require('util'), + _ = require('underscore'); // override debug.log to print only as console.log 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; function cleanExit() { @@ -36,25 +37,25 @@ function start() { function runTestsIfNeeded(callback) { debug('Getting latest box version'); - getLatestBoxVersion(function (error, latestETag, latestBoxVersion, lastModified) { + getLatestBoxVersion(function (error, latestVersionInfo) { if (error) return callback(error); - if (lastModified === gLastModified) { - debug('Box version has not changed. etag:%s lm:%s', latestETag, lastModified); + if (_.isEqual(gLatestVersionInfo, latestVersionInfo)) { + debug('Box version has not changed'); 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 debug('Waiting for appstore gets the new release. diff=%s', diff); return callback(); } - runTests(latestETag, latestBoxVersion, lastModified, function (error) { - debug('Finished running tests for etag %s / lm %s: %s', latestETag, lastModified, error); - gLastModified = lastModified; + runTests(latestVersionInfo, function (error) { + debug('Finished running tests for %j %s', latestVersionInfo, error); + gLatestVersionInfo = latestVersionInfo; callback(error); }); }); @@ -67,26 +68,25 @@ function getLatestBoxVersion(callback) { return callback(new Error('Error downloading versions file')); } - var latestVersion = Object.keys(res.body).sort(semver.rcompare)[0]; - var latestETag = res.headers['etag']; - var lastModified = new Date(res.headers['last-modified']); + var latestVersionInfo = Object.keys(res.body).sort(semver.rcompare)[0]; - 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) { - var topic = util.format('box version: %s etag: %s lastModified:%s', latestBoxVersion, latestETag, lastModified); - - debug('Running tests for %s', topic); +function runTests(latestVersionInfo, callback) { + debug('Running tests for %j', latestVersionInfo); gNpmTest = shell.system('e2etestrunner', 'npm test', function (error, stdout, stderr) { gNpmTest = null; 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); }); } diff --git a/mailer.js b/mailer.js index 0b1b72f..0751c8a 100644 --- a/mailer.js +++ b/mailer.js @@ -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); var mailOptions = { to: 'admin@cloudron.io', - subject: util.format('E2E test results for box %s', topic), - text: 'stdout\n------\n' + stdout.toString('utf8') + '\n\nstderr\n------\n' + stderr.toString('utf8') + '\n\n' + subject: util.format('E2E test results for %s', topic), + text: versionInfo + '\n\nstdout\n------\n' + stdout.toString('utf8') + '\n\nstderr\n------\n' + stderr.toString('utf8') + '\n\n' }; send(mailOptions, callback); diff --git a/package.json b/package.json index 3d933f1..5cdf6b0 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "superagent": "^1.2.0", "superagent-sync": "^0.1.0", "supererror": "^0.7.0", - "terminate": "^1.0.5" + "terminate": "^1.0.5", + "underscore": "^1.8.3" } }