Skip to content

Commit

Permalink
Updated to make matchUntilHalt test is determinate
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed Feb 27, 2013
1 parent 56da7e8 commit 3fc8fbb
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions test/flow.test.js
Expand Up @@ -324,14 +324,36 @@ it.describe("Flow",function (it) {
this.message = m;
}

function Count(c) {
this.count = c;
}

var session, flow = nools.flow("Halt Flow", function (flow) {
flow.rule("Hello", [Message, "m", "m.message =~ /^hello(\\s*world)?$/"], function (facts) {

flow.rule("Stop", [Count, "c", "c.count == 10"], function () {
this.halt();
});

flow.rule("Hello", [
[Count, "c"],
[Message, "m", "m.message =~ /^hello(\\s*world)?$/"]
], function (facts) {
this.modify(facts.m, function () {
this.message += " goodbye";
});
this.modify(facts.c, function () {
this.count++;
});
});

flow.rule("Goodbye", [Message, "m", "m.message =~ /.*goodbye$/"], function () {
flow.rule("Goodbye", [
[Count, "c"],
[Message, "m", "m.message =~ /.*goodbye$/"]
], function (facts) {
this.retract(facts.m);
this.modify(facts.c, function () {
this.count++;
});
});

});
Expand All @@ -341,21 +363,18 @@ it.describe("Flow",function (it) {
});

it.should("match until halt is called", function () {
var count = 0, called = 0;
session.on("fire", function () {
called++;
});
var count = 0, called = new Count(0);
var interval = setInterval(function () {
if (count++ >= 5) {
clearInterval(interval);
session.halt();
} else {
session.assert(new Message("hello"));
}
}, 100);
return session.matchUntilHalt(function (err) {
assert.isNull(err);
assert.equal(called, 10);
session.assert(called);
return session.matchUntilHalt().then(function (err) {
assert.isUndefinedOrNull(err);
assert.equal(called.count, 10);
});

});
Expand Down

0 comments on commit 3fc8fbb

Please sign in to comment.