Permalink
Browse files

Update post-update.js so that it exits with the same exit code as run…

…-all.js. Depend on this exit code making back to testy eventually so that test_selenium can exit with the same exit code and travis correctly marks the tests as pass/fail.
  • Loading branch information...
1 parent 605ba30 commit 169427f5795956d4393361411fdb16d23ee6acfc @shane-tomlinson shane-tomlinson committed Nov 13, 2012
Showing with 43 additions and 50 deletions.
  1. +27 −35 automation-tests/scripts/post-update.js
  2. +16 −15 scripts/test_selenium
@@ -6,26 +6,12 @@
const child_process = require("child_process"),
- util = require('util'),
fs = require("fs"),
- path = require("path");
-
-function extend() {
- var extended = {};
- var extensions = Array.prototype.slice.call(arguments, 0);
- extensions.forEach(function(extension) {
- for (var key in extension) {
- if (typeof extension[key] !== "undefined") {
- extended[key] = extension[key];
- }
- }
- });
-
- return extended;
-}
+ path = require("path"),
+ toolbelt = require("../lib/toolbelt");
function installDependencies(done) {
- util.log(">> Installing selenium test dependencies");
+ console.log(">> Installing selenium test dependencies");
var installProcess = child_process.spawn("npm", ["install"], {
cwd: path.join(__dirname, ".."),
@@ -34,20 +20,29 @@ function installDependencies(done) {
installProcess.stdout.pipe(process.stdout);
installProcess.stderr.pipe(process.stderr);
-
installProcess.on('exit', done);
}
-function getTestEnvironment() {
- var sauceConfigPath = path.join(__dirname, "..", "..", "..", "sauce.json");
- var sauceConfig = JSON.parse(fs.readFileSync(sauceConfigPath, 'utf8'));
+function getJSONConfig(name) {
+ try {
+ var configPath = path.join(__dirname, "..", "..", "..", name);
+ var config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
+ } catch(e) {
+ console.error("cannot read " + name + " or json is invalid");
+ process.exit(1);
+ }
- var globalConfigPath = path.join(__dirname, "..", "..", "..", "config.json");
- var globalConfig = JSON.parse(fs.readFileSync(globalConfigPath, 'utf8'));
+ return config;
+}
+
+function getTestEnvironment() {
+ // the next two will exit the process if they fail.
+ var sauceConfig = getJSONConfig("sauce.json"),
+ globalConfig = getJSONConfig("config.json"),
+ // personaEnv is the name of the ephemeral instance
+ personaEnv = globalConfig.public_url.replace("https://", '').replace(".personatest.org", "");
- // get the name of the instance.
- var personaEnv = globalConfig.public_url.replace("https://", '').replace(".personatest.org", "");
- var env = extend(process.env, {
+ var env = toolbelt.copyExtendEnv({
RUNNERS: sauceConfig.runners,
PERSONA_ENV: personaEnv,
PERSONA_SAUCE_USER: sauceConfig.persona_sauce_user,
@@ -59,9 +54,8 @@ function getTestEnvironment() {
return env;
}
-function runTests(done) {
- var env = getTestEnvironment();
- util.log(">> Running tests against " + env.PERSONA_ENV);
+function runTests(env, done) {
+ console.log(">> Running tests against " + env.PERSONA_ENV);
var runnerPath = path.join(__dirname, "run-all.js");
var testProcess = child_process.spawn("node", [ runnerPath ], {
@@ -70,15 +64,13 @@ function runTests(done) {
testProcess.stdout.pipe(process.stdout);
testProcess.stderr.pipe(process.stderr);
-
- testProcess.on('exit', function(code) {
- console.log("done", code);
- done && done();
- });
+ testProcess.on('exit', done);
}
+var env = getTestEnvironment();
installDependencies(function() {
- runTests(function(code) {
+ runTests(env, function(code) {
+ console.log(">> Exiting tests with code: " + code);
process.exit(code);
});
});
View
@@ -6,9 +6,10 @@
// This is a travis-ci specific script that triggers selenium test runs on
-// testy-listener.personatest.org.
+// testy-listener.personatest.org. It does this by issueing a curl POST command to testy-listner.personatest.org with the repo's url and sha. testy then goes and fetches the repo, checks out the sha, creates an ephemeral deployment, and then collects the test results which are then reported here.
const spawn = require('child_process').spawn,
+ path = require('path'),
testy_url = process.env['TESTY_URL'] || 'http://testy-listener.personatest.org/test',
repo_url = process.env['REPO_URL'],
repo_sha = process.env['REPO_SHA'];
@@ -77,25 +78,25 @@ function runTests(repo, sha, done) {
p.stdout.pipe(process.stdout);
p.stderr.pipe(process.stderr);
- p.on('exit', function(code, signal) {
- if (!code) {
- code = searchForErrors(buf) ? 1 : 0;
- }
- done && done(null, code);
+ p.on('exit', function(exit_code, signal) {
+ done && done(null, getCode(exit_code, buf));
});
}
-function searchForErrors(buf) {
- // make sure at least one testsuite was run but there are no errors.
- return buf.indexOf("</testsuite>") === -1
- // If the errors attribute has anything but a 0, there is a real error.
- || /errors="[123456789].*/.test(buf)
- || /failures="[123456789].*/.test(buf);
+function getCode(exit_code, buf) {
+ // If there already exists a code, use it.
+ if (!exit_code) {
+ // search for the exiting post-install message, return the code.
+ // If the code does not exist, assume failure and return 127
+ var result = (/Exiting tests with code: (\d+)/g).exec(buf);
+ exit_code = parseInt(result && result[1] || 127, 10);
+ }
+ return exit_code;
}
getRepoInfo(function(info) {
- runTests(info.repo, info.sha, function(err, status) {
- console.log("\nexiting with code:", status);
- process.exit(status);
+ runTests(info.repo, info.sha, function(err, code) {
+ console.log("\nExiting " + path.basename(__filename) + " with code:", code);
+ process.exit(code);
});
});

0 comments on commit 169427f

Please sign in to comment.