Skip to content

Commit

Permalink
Prevent transient failures caused by slow test execution.
Browse files Browse the repository at this point in the history
Testling would occasionally fail the `Promise.race` test because test
execution on the browser under test was so slow that all the delayed
promises would complete "at once".  Ensure that even if this happens
the test gives the correct answer.
  • Loading branch information
cscott committed Mar 4, 2014
1 parent c3211ab commit 664a831
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/promise/race.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ describe("Promise.race", function () {
});

it("should settle in the same way as the first promise to settle", function (done) {
var iterable = [delayPromise(1, 1000), delayPromise(2, 200), delayPromise(3, 500)];
// ensure that even if timeouts are delayed an all execute together,
// p2 will settle first.
var p2 = delayPromise(2, 200);
var p1 = delayPromise(1, 1000);
var p3 = delayPromise(3, 500);
var iterable = [p1, p2, p3];

Promise.race(iterable).then(function (value) {
assert.strictEqual(value, 2);
Expand Down

0 comments on commit 664a831

Please sign in to comment.