Skip to content

Commit

Permalink
behavior fixed for cleaning tmp directory
Browse files Browse the repository at this point in the history
  • Loading branch information
lzatorski committed Nov 15, 2013
1 parent 09dd0d5 commit 76847fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
19 changes: 9 additions & 10 deletions lib/launchers/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ var BEING_TIMEOUTED = 5;
var BaseBrowser = function(id, emitter, captureTimeout, retryLimit) {
var self = this;
var capturingUrl;
var exitCallback = function() {};
var exitCallbacks = [];

this.killTimeout = 2000;
this.id = id;
this.state = null;
this._tempDir = path.normalize((env.TMPDIR || env.TMP || env.TEMP || '/tmp') + '/karma-' +
id.toString());
this.exitCallbacks = [];


this.start = function(url) {
capturingUrl = url;
Expand Down Expand Up @@ -61,17 +59,17 @@ var BaseBrowser = function(id, emitter, captureTimeout, retryLimit) {


this.kill = function(callback) {
exitCallback = callback || function() {};
var exitCallback = callback || function() {};

log.debug('Killing %s', self.name);
if (self.state === FINISHED) {
process.nextTick(exitCallback);
} else if (self.state === BEING_KILLED) {
this.exitCallbacks.push(exitCallback);
exitCallbacks.push(exitCallback);
} else {
self.state = BEING_KILLED;
self._process.kill();
this.exitCallbacks.push(exitCallback);
exitCallbacks.push(exitCallback);
setTimeout(self._onKillTimeout, self.killTimeout);
}
};
Expand Down Expand Up @@ -184,11 +182,12 @@ var BaseBrowser = function(id, emitter, captureTimeout, retryLimit) {
}

self.state = FINISHED;
self.exitCallbacks.forEach(function(exitCallback) {
exitCallback();
self._cleanUpTmp(function(err) {
exitCallbacks.forEach(function(exitCallback) {
exitCallback(err);
});
exitCallbacks = [];
});
self.exitCallbacks = [];
self._cleanUpTmp(exitCallback);
};


Expand Down
3 changes: 1 addition & 2 deletions test/unit/launchers/Base.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ describe 'launchers Base', ->
expect(killSpy).not.to.have.been.called

mockSpawn._processes[0].emit 'close', 0
expect(mockRimraf).to.have.been.calledWith path.normalize('/tmp/karma-12345'), killSpy

expect(mockRimraf).to.have.been.calledWith path.normalize('/tmp/karma-12345')
mockRimraf._callbacks[0]() # rm tempdir
expect(killSpy).to.have.been.called

Expand Down

0 comments on commit 76847fe

Please sign in to comment.