From c70eba32372488d89506fe8cfbac2427d509af87 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Sat, 8 Mar 2014 01:06:08 +0100 Subject: [PATCH] fixed async flaw in test runner silly flow problem could bypass concurrency limits --- _infrastructure/tests/runner.js | 19 +++++++++---------- _infrastructure/tests/runner.ts | 13 +++++-------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/_infrastructure/tests/runner.js b/_infrastructure/tests/runner.js index 649569923..9d6830f67 100644 --- a/_infrastructure/tests/runner.js +++ b/_infrastructure/tests/runner.js @@ -1035,9 +1035,6 @@ var DT; // add a closure to queue this.queue.push(function () { - // when activate, add test to active list - _this.active.push(test); - // run it var p = test.run(); p.then(defer.resolve.bind(defer), defer.reject.bind(defer)); @@ -1048,6 +1045,9 @@ var DT; } _this.step(); }); + + // return it + return test; }); this.step(); @@ -1056,13 +1056,9 @@ var DT; }; TestQueue.prototype.step = function () { - var _this = this; - // setTimeout to make it flush - setTimeout(function () { - while (_this.queue.length > 0 && _this.active.length < _this.concurrent) { - _this.queue.pop().call(null); - } - }, 1); + while (this.queue.length > 0 && this.active.length < this.concurrent) { + this.active.push(this.queue.pop().call(null)); + } }; return TestQueue; })(); @@ -1314,4 +1310,7 @@ var DT; process.exit(2); }); })(DT || (DT = {})); +//grunt-start +/// +//grunt-end //# sourceMappingURL=runner.js.map diff --git a/_infrastructure/tests/runner.ts b/_infrastructure/tests/runner.ts index 6e71d621a..ad3a77909 100644 --- a/_infrastructure/tests/runner.ts +++ b/_infrastructure/tests/runner.ts @@ -75,8 +75,6 @@ module DT { var defer = Promise.defer(); // add a closure to queue this.queue.push(() => { - // when activate, add test to active list - this.active.push(test); // run it var p = test.run(); p.then(defer.resolve.bind(defer), defer.reject.bind(defer)); @@ -87,6 +85,8 @@ module DT { } this.step(); }); + // return it + return test; }); this.step(); // defer it @@ -94,12 +94,9 @@ module DT { } private step(): void { - // setTimeout to make it flush - setTimeout(() => { - while (this.queue.length > 0 && this.active.length < this.concurrent) { - this.queue.pop().call(null); - } - }, 1); + while (this.queue.length > 0 && this.active.length < this.concurrent) { + this.active.push(this.queue.pop().call(null)); + } } }