fixed async flaw in test runner

silly flow problem could bypass concurrency limits
This commit is contained in:
Bart van der Schoor
2014-03-08 01:06:08 +01:00
parent 5aea981b63
commit c70eba3237
2 changed files with 14 additions and 18 deletions
+9 -10
View File
@@ -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
/// <reference path="../runner.ts" />
//grunt-end
//# sourceMappingURL=runner.js.map
+5 -8
View File
@@ -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));
}
}
}