definition-tester
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -10,3 +10,7 @@ ///////////////////////////////// | ||
DefaultTestReporter.prototype.printPositiveCharacter = function (testResult) { | ||
this.print.out('\33[36m\33[1m' + '.' + '\33[0m'); | ||
if (testResult.attempts > 1) { | ||
this.print.out('\33[36m\33[1m' + testResult.attempts + '\33[0m'); | ||
} else { | ||
this.print.out('\33[36m\33[1m' + '.' + '\33[0m'); | ||
} | ||
this.index++; | ||
@@ -13,0 +17,0 @@ this.printBreakIfNeeded(this.index); |
var Promise = require('bluebird'); | ||
var TestRunItem = (function () { | ||
function TestRunItem(test) { | ||
this.attempts = 1; | ||
this.test = test; | ||
this.defer = Promise.defer(); | ||
} | ||
return TestRunItem; | ||
})(); | ||
///////////////////////////////// | ||
@@ -7,37 +15,59 @@ // Parallel execute Tests | ||
function TestQueue(concurrent) { | ||
this.retries = []; | ||
this.queue = []; | ||
this.active = []; | ||
this.concurrent = Math.max(1, concurrent); | ||
this.maxRetry = 3; | ||
this.maxConcurrent = Math.max(1, concurrent); | ||
this.concurrent = this.maxConcurrent; | ||
} | ||
// add to queue and return a promise | ||
TestQueue.prototype.run = function (test) { | ||
var item = new TestRunItem(test); | ||
this.queue.push(item); | ||
this.check(); | ||
return item.defer.promise; | ||
}; | ||
TestQueue.prototype.check = function () { | ||
while (this.queue.length > 0 && this.active.length < this.concurrent) { | ||
this.step(); | ||
} | ||
// when done go for retries | ||
if (this.queue.length === 0 && this.active.length === 0 && this.retries.length > 0) { | ||
this.queue = this.retries; | ||
this.retries = []; | ||
// lower the concurrency (fight memory errors) | ||
this.concurrent = Math.max(1, this.concurrent / 2); | ||
// check again | ||
this.check(); | ||
} | ||
}; | ||
TestQueue.prototype.step = function () { | ||
var _this = this; | ||
var defer = Promise.defer(); | ||
// add a closure to queue | ||
this.queue.push(function () { | ||
// run it | ||
var p = test.run(); | ||
p.then(defer.resolve.bind(defer), defer.reject.bind(defer)); | ||
p.finally(function () { | ||
var i = _this.active.indexOf(test); | ||
if (i > -1) { | ||
_this.active.splice(i, 1); | ||
var item = this.queue.pop(); | ||
item.test.run().then(function (res) { | ||
// see if we can retry | ||
if (!res.success && item.attempts < _this.maxRetry) { | ||
if (res.stdout && /^Killed/.test(res.stdout)) { | ||
item.attempts++; | ||
_this.retries.push(item); | ||
return; | ||
} | ||
_this.step(); | ||
} | ||
res.attempts = item.attempts; | ||
item.defer.resolve(res); | ||
}).catch(function (err) { | ||
item.defer.reject(err); | ||
}).finally(function () { | ||
var i = _this.active.indexOf(item); | ||
if (i > -1) { | ||
_this.active.splice(i, 1); | ||
} | ||
process.nextTick(function () { | ||
_this.check(); | ||
}); | ||
// return it | ||
return test; | ||
}); | ||
this.step(); | ||
// defer it | ||
return defer.promise; | ||
this.active.push(item); | ||
}; | ||
TestQueue.prototype.step = function () { | ||
while (this.queue.length > 0 && this.active.length < this.concurrent) { | ||
// console.log([this.queue.length, this.active.length, this.concurrent]); | ||
this.active.push(this.queue.pop().call(null)); | ||
} | ||
}; | ||
return TestQueue; | ||
})(); | ||
module.exports = TestQueue; |
@@ -6,2 +6,3 @@ ///////////////////////////////// | ||
function TestResult() { | ||
this.attempts = 1; | ||
} | ||
@@ -8,0 +9,0 @@ Object.defineProperty(TestResult.prototype, "success", { |
{ | ||
"name": "definition-tester", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "DefinitelyTyped repository testing infrastructure", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
58915
1470