mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Add job throttle to test/saucelabs.js.
This commit is contained in:
@@ -65,12 +65,14 @@ var advisor = getOption('advisor', true),
|
|||||||
maxDuration = getOption('maxDuration', 360),
|
maxDuration = getOption('maxDuration', 360),
|
||||||
port = ports[Math.min(_.sortedIndex(ports, getOption('port', 9001)), ports.length - 1)],
|
port = ports[Math.min(_.sortedIndex(ports, getOption('port', 9001)), ports.length - 1)],
|
||||||
publicAccess = getOption('public', true),
|
publicAccess = getOption('public', true),
|
||||||
|
queueTimeout = getOption('queueTimeout', 360),
|
||||||
recordVideo = getOption('recordVideo', true),
|
recordVideo = getOption('recordVideo', true),
|
||||||
recordScreenshots = getOption('recordScreenshots', false),
|
recordScreenshots = getOption('recordScreenshots', false),
|
||||||
runner = getOption('runner', 'test/index.html').replace(/^\W+/, ''),
|
runner = getOption('runner', 'test/index.html').replace(/^\W+/, ''),
|
||||||
runnerUrl = getOption('runnerUrl', 'http://localhost:' + port + '/' + runner),
|
runnerUrl = getOption('runnerUrl', 'http://localhost:' + port + '/' + runner),
|
||||||
statusInterval = getOption('statusInterval', 5000),
|
statusInterval = getOption('statusInterval', 5000),
|
||||||
tags = getOption('tags', []),
|
tags = getOption('tags', []),
|
||||||
|
throttled = getOption('throttled', 10),
|
||||||
tunneled = getOption('tunneled', true),
|
tunneled = getOption('tunneled', true),
|
||||||
tunnelId = getOption('tunnelId', 'tunnel_' + env.TRAVIS_JOB_NUMBER),
|
tunnelId = getOption('tunnelId', 'tunnel_' + env.TRAVIS_JOB_NUMBER),
|
||||||
tunnelTimeout = getOption('tunnelTimeout', 10000),
|
tunnelTimeout = getOption('tunnelTimeout', 10000),
|
||||||
@@ -87,8 +89,6 @@ var browserNameMap = {
|
|||||||
/** List of platforms to load the runner on */
|
/** List of platforms to load the runner on */
|
||||||
var platforms = [
|
var platforms = [
|
||||||
['Linux', 'android', '4.3'],
|
['Linux', 'android', '4.3'],
|
||||||
['Linux', 'android', '4.2'],
|
|
||||||
['Linux', 'android', '4.1'],
|
|
||||||
['Linux', 'android', '4.0'],
|
['Linux', 'android', '4.0'],
|
||||||
['Windows 8.1', 'firefox', '28'],
|
['Windows 8.1', 'firefox', '28'],
|
||||||
['Windows 8.1', 'firefox', '27'],
|
['Windows 8.1', 'firefox', '27'],
|
||||||
@@ -319,7 +319,7 @@ function onCheck(error, response, body) {
|
|||||||
failures = _.result(result, 'failed'),
|
failures = _.result(result, 'failed'),
|
||||||
label = options.name + ':';
|
label = options.name + ':';
|
||||||
|
|
||||||
if (!completed && !(data.status != 'test session in progress' && elapsed >= idleTimeout)) {
|
if (!completed && !(data.status != 'test session in progress' && elapsed >= queueTimeout)) {
|
||||||
setTimeout(check.bind(this), statusInterval);
|
setTimeout(check.bind(this), statusInterval);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -408,7 +408,7 @@ Job.prototype.run = function() {
|
|||||||
* @param {Function} onComplete The function called once all jobs have completed.
|
* @param {Function} onComplete The function called once all jobs have completed.
|
||||||
*/
|
*/
|
||||||
function run(platforms, onComplete) {
|
function run(platforms, onComplete) {
|
||||||
var jobs = _.map(platforms, function(platform) {
|
var queue = _.map(platforms, function(platform) {
|
||||||
return new Job({
|
return new Job({
|
||||||
'user': username,
|
'user': username,
|
||||||
'pass': accessKey,
|
'pass': accessKey,
|
||||||
@@ -416,20 +416,32 @@ function run(platforms, onComplete) {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
var finishedJobs = 0,
|
var dequeue = function() {
|
||||||
success = true,
|
while (queue.length && running < throttled) {
|
||||||
totalJobs = jobs.length;
|
running++;
|
||||||
|
queue.shift().run();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
_.invoke(jobs, 'on', 'complete', function() {
|
var completed = 0,
|
||||||
if (++finishedJobs == totalJobs) {
|
running = 0,
|
||||||
onComplete(success);
|
success = true,
|
||||||
} else if (success) {
|
total = queue.length;
|
||||||
|
|
||||||
|
_.invoke(queue, 'on', 'complete', function() {
|
||||||
|
running--;
|
||||||
|
if (success) {
|
||||||
success = !this.failed;
|
success = !this.failed;
|
||||||
}
|
}
|
||||||
|
if (++completed == total) {
|
||||||
|
onComplete(success);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dequeue();
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Starting jobs...');
|
console.log('Starting jobs...');
|
||||||
_.invoke(jobs, 'run');
|
dequeue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// cleanup any inline logs when exited via `ctrl+c`
|
// cleanup any inline logs when exited via `ctrl+c`
|
||||||
|
|||||||
Reference in New Issue
Block a user