First installment of 'meteor run' tests.

Tests meteor --once and restarting on upgrade.
This commit is contained in:
Geoff Schmidt
2014-01-29 02:02:17 -08:00
parent 377d940ba0
commit e1994f6ece
15 changed files with 223 additions and 52 deletions

View File

@@ -0,0 +1 @@
local

View File

@@ -0,0 +1,6 @@
# Meteor packages used by this project, one per line.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
standard-app-packages

View File

@@ -0,0 +1 @@
none

View File

@@ -0,0 +1,19 @@
process.stdout.write("once test\n");
if (process.env.RUN_ONCE_OUTCOME === "exit")
process.exit(123);
if (process.env.RUN_ONCE_OUTCOME === "kill") {
process.kill(process.pid, 'SIGKILL');
}
if (process.env.RUN_ONCE_OUTCOME === "hang") {
// The outstanding timeout will prevent node from exiting
setTimeout(function () {}, 365 * 24 * 60 * 60);
}
if (process.env.RUN_ONCE_OUTCOME === "mongo") {
var test = new Meteor.Collection('test');
test.insert({ value: 86 });
process.exit(test.findOne().value);
}

View File

@@ -0,0 +1 @@
.build*

View File

@@ -0,0 +1,2 @@
process.stdout.write("other program\n");
process.exit(44);

View File

@@ -0,0 +1,7 @@
Package.describe({
summary: "another program, for testing"
});
Package.on_use(function (api) {
api.add_files(["other.js"], 'server');
});

View File

@@ -111,7 +111,7 @@ selftest.define("checkout", ['checkout'], function () {
s.write(".meteor/release", "something");
run = s.run("list", "--using");
run.readErr("=> Running Meteor from a checkout");
run.matchErr("project version (something)\n\n");
run.matchErr("project version (something)\n");
run.expectExit(0);
});

View File

@@ -1,17 +1,151 @@
var selftest = require('../selftest.js');
var Sandbox = selftest.Sandbox;
var utils = require('../utils.js');
selftest.define("x", function () {
var MONGO_LISTENING =
{ stdout: " [initandlisten] waiting for connections on port" };
var SIMPLE_WAREHOUSE = {
v1: { tools: 'tools1' },
v2: { tools: 'tools1', latest: true },
v3: { tools: 'tools1' },
};
selftest.define("run --once", function () {
var s = new Sandbox({ fakeMongo: true });
var run;
s.createApp("onceapp", "once");
s.cd("onceapp");
// Basic run --once
s.set("RUN_ONCE_OUTCOME", "exit");
run = s.run("--once");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(5);
run.match("once test\n");
run.expectExit(123);
// run --once, exit on signal
s.set("RUN_ONCE_OUTCOME", "kill");
run = s.run("--once");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(5);
run.match("once test\n");
run.matchErr("Killed (SIGKILL)\n");
run.expectExit(255);
// run --once, bundle failure
s.set("RUN_ONCE_OUTCOME", "exit");
s.write("junk.js", "]");
run = s.run("--once");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(5);
run.matchErr("Build failed");
run.matchErr("Unexpected token");
run.expectExit(254);
s.unlink("junk.js");
// file changes don't make it restart
s.set("RUN_ONCE_OUTCOME", "hang");
run = s.run("--once");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(5);
run.match("once test\n");
s.write('empty.js', 'null');
s.write('.meteor/release', 'v1');
utils.sleep(2); // sorry, hard to avoid
run.stop();
run.forbidAll("updated");
s.unlink('empty.js');
s.write('.meteor/release', 'none');
// running a different program
run = s.run("--once", "--program", "other");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(5);
run.match("other program\n");
run.expectExit(44);
// bad program name
run = s.run("--once", "--program", "xyzzy");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(5);
run.match("xyzzy");
run.expectExit(254);
// Try it with a real Mongo. Make sure that it actually starts one.
s = new Sandbox;
s.createApp("onceapp", "once");
s.cd("onceapp");
s.set("RUN_ONCE_OUTCOME", "mongo");
run = s.run("--once");
run.waitSecs(5);
run.expectExit(86);
});
selftest.define("update during run", ["checkout"], function () {
var s = new Sandbox({
warehouse: SIMPLE_WAREHOUSE,
fakeMongo: true
});
var run;
s.createApp("myapp", "empty");
s.cd("myapp");
var run = s.run();
run.match('');
run.tellMongo({ stdout: " [initandlisten] waiting for connections on port" });
run.tellMongo({ exit: 99 });
run.waitSecs(0);
run.expectExit(123);
// If the app version changes, we exit with an error message.
s.write('.meteor/release', 'v1');
run = s.run();
run.tellMongo(MONGO_LISTENING);
run.waitSecs(2)
run.match('localhost:3000');
s.write('.meteor/release', 'v2');
run.matchErr('to Meteor v2 from Meteor v1');
run.expectExit(254);
// But not if the release was forced (case 1)
s.write('.meteor/release', 'v1');
run = s.run("--release", "v3");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(2)
run.match('localhost:3000');
s.write('.meteor/release', 'v2');
s.write('empty.js', '');
run.waitSecs(2)
run.match('restarted');
run.stop();
run.forbidAll("updated");
// But not if the release was forced (case 2)
s.write('.meteor/release', 'v1');
run = s.run("--release", "v1");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(2)
run.match('localhost:3000');
s.write('.meteor/release', 'v2');
s.write('empty.js', '');
run.waitSecs(2)
run.match('restarted');
run.stop();
run.forbidAll("updated");
// Nor do we do it if you're running from a checkout
s = new Sandbox({ fakeMongo: true });
s.createApp("myapp", "empty");
s.cd("myapp");
s.write('.meteor/release', 'v1');
run = s.run();
run.tellMongo(MONGO_LISTENING);
run.waitSecs(2)
run.match('localhost:3000');
s.write('.meteor/release', 'v2');
s.write('empty.js', '');
run.waitSecs(2)
run.match('restarted');
run.stop();
run.forbidAll("updated");
});