Give each test run a unique ID

This commit is contained in:
Geoff Schmidt
2012-03-02 02:32:32 -08:00
parent 60913bfd6f
commit bc69d57e16
2 changed files with 14 additions and 9 deletions

View File

@@ -187,25 +187,23 @@ testAsyncMulti("livedata - basic method invocation", [
var checkBalances = function (a, b) {
var alice = Ledger.findOne({name: "alice", world: world});
var bob = Ledger.findOne({name: "bob", world: world});
var alice = Ledger.findOne({name: "alice", world: test.runId()});
var bob = Ledger.findOne({name: "bob", world: test.runId()});
assert.equal(alice.balance, a);
assert.equal(bob.balance, b);
}
// would be nice to have a database-aware test harness of some kind --
// this is a big hack (and XXX pollutes the global test namespace)
var world;
testAsyncMulti("livedata - compound methods", [
function () {
world = LocalCollection.uuid();
if (Meteor.is_client)
Meteor.subscribe("ledger", {world: world});
Ledger.insert({name: "alice", balance: 100, world: world});
Ledger.insert({name: "bob", balance: 50, world: world});
Meteor.subscribe("ledger", {world: test.runId()});
Ledger.insert({name: "alice", balance: 100, world: test.runId()});
Ledger.insert({name: "bob", balance: 50, world: test.runId()});
},
function (expect) {
App.call('ledger/transfer', world, "alice", "bob", 10,
App.call('ledger/transfer', test.runId(), "alice", "bob", 10,
expect(undefined, undefined));
checkBalances(90, 60);
@@ -217,7 +215,7 @@ testAsyncMulti("livedata - compound methods", [
});
},
function (expect) {
App.call('ledger/transfer', world, "alice", "bob", 100, true,
App.call('ledger/transfer', test.runId(), "alice", "bob", 100, true,
expect(failure(409)));
if (Meteor.is_client)

View File

@@ -80,6 +80,7 @@ Meteor._TestRun = function (manager, onReport) {
self.current_fail_count = null;
self.stop_at_offset = null;
self.current_onException = null;
self.id = Meteor.uuid();
_.each(self.manager.ordered_tests, _.bind(self._report, self));
};
@@ -343,6 +344,12 @@ _.extend(globals.test, {
exception: function (exception) {
test._currentRun.get().exception(exception);
},
// returns a unique ID for this test run, for convenience use by
// your tests
runId: function () {
return test._currentRun.get().id;
}
});