Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
fix: wait for the browserstack worker to be in state 'running' before…
Browse files Browse the repository at this point in the history
… timing out.
  • Loading branch information
inspector-ambitious committed Oct 4, 2013
1 parent 9453045 commit f8a3cc0
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,42 @@ var BrowserStackBrowser = function(id, emitter, args, logger,
this.url = url;
tunnel.then(function() {
client.createWorker(settings, function(error, worker) {

if (error) {
log.error('Can not start %s\n %s', browserName, formatError(error));
return emitter.emit('browser_process_failure', self);
}

log.debug('Browser %s started with id %s', browserName, worker.id);
workerId = worker.id;

if (captureTimeout) {
setTimeout(self._onTimeout, captureTimeout);
var whenRunning = function() {
log.debug('%s job started with id %s', browserName, workerId);

if (captureTimeout) {
setTimeout(self._onTimeout, captureTimeout);
}
};

var waitForWorkerRunning = function() {
client.getWorker(workerId, function(error, w) {
if (error) {
log.error('Can not get worker %s status %s\n %s', workerId, browserName, formatError(error));
return emitter.emit('browser_process_failure', self);
}
if (w.status === 'running') {
whenRunning();
} else {
log.debug('%s job with id %s still in queue.', browserName, workerId);
setTimeout(waitForWorkerRunning, 1000);
}
});
};

if (worker.status === 'running') {
whenRunning();
} else {
log.debug('%s job queued with id %s.', browserName, workerId);
setTimeout(waitForWorkerRunning, 1000);
}

});
Expand Down

0 comments on commit f8a3cc0

Please sign in to comment.