Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
fix up
Browse files Browse the repository at this point in the history
  • Loading branch information
rostik404 committed Aug 30, 2016
1 parent f43061d commit 511b5c9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
8 changes: 8 additions & 0 deletions lib/runner/browser-runner/browser-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ var BrowserAgent = inherit({
__constructor: function(browserId, pool) {
this.browserId = browserId;
this._pool = pool;
this._force = false;
},

invalidateSession: function() {
this._force = true;
},

getBrowser: function() {
return this._pool.getBrowser(this.browserId);
},

freeBrowser: function(browser, opts) {
opts = opts || {};
opts.force = this._force;

return this._pool.freeBrowser(browser, opts);
}
}, {
Expand Down
12 changes: 5 additions & 7 deletions lib/runner/suite-runner/regular-suite-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = class RegularSuiteRunner extends SuiteRunner {

this._config = config;
this._session = null;
this._force = false;
}

_doRun(stateProcessor) {
Expand All @@ -32,7 +31,7 @@ module.exports = class RegularSuiteRunner extends SuiteRunner {

return this._passErrorToStates(e);
})
.fin(() => this._session && this._browserAgent.freeBrowser(this._session.browser, {force: this._force}));
.fin(() => this._session && this._browserAgent.freeBrowser(this._session.browser));
}

_initSession(browser) {
Expand Down Expand Up @@ -95,7 +94,7 @@ module.exports = class RegularSuiteRunner extends SuiteRunner {

_handleError(error) {
if (!(error instanceof NoRefImageError)) {
this._force = true;
this._browserAgent.invalidateSession();
}
}

Expand All @@ -109,14 +108,13 @@ module.exports = class RegularSuiteRunner extends SuiteRunner {
RunnerEvents.TEST_RESULT,
RunnerEvents.CAPTURE,
RunnerEvents.UPDATE_RESULT,
RunnerEvents.WARNING,
RunnerEvents.ERROR
RunnerEvents.WARNING
]);

this.on(RunnerEvents.ERROR, (e) => {
runner.on(RunnerEvents.ERROR, (e) => {
this._handleError(e);

this.passthroughEvent(runner, RunnerEvents.ERROR);
this.emit(RunnerEvents.ERROR, e);
});

return runner.run(stateProcessor);
Expand Down
17 changes: 17 additions & 0 deletions test/unit/runner/browser-runner/browser-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,21 @@ describe('runner/browser-runner/browser-agent', function() {

assert.calledWith(browserPool.freeBrowser, browser);
});

it('should free browser unconditionally if session was invalidated', () => {
const browserAgent = BrowserAgent.create('browser', browserPool);

browserAgent.invalidateSession();
browserAgent.freeBrowser();

assert.calledWith(browserPool.freeBrowser, sinon.match.any, {force: true});
});

it('should free browser conditionally if session was not invalidated', () => {
const browserAgent = BrowserAgent.create('browser', browserPool);

browserAgent.freeBrowser();

assert.calledWith(browserPool.freeBrowser, sinon.match.any, {force: false});
});
});
10 changes: 5 additions & 5 deletions test/unit/runner/suite-runner/regular-suite-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const StateRunner = require('lib/runner/state-runner/state-runner');
const CaptureSession = require('lib/capture-session');
const BrowserAgent = require('lib/runner/browser-runner/browser-agent');
const Config = require('lib/config');
const util = require('../../../util');
const NoRefImageError = require('lib/errors/no-ref-image-error');
const util = require('../../../util');
const makeSuiteStub = util.makeSuiteStub;

describe('runner/suite-runner/regular-suite-runner', () => {
Expand Down Expand Up @@ -435,21 +435,21 @@ describe('runner/suite-runner/regular-suite-runner', () => {
.fail(() => assert.calledOnce(BrowserAgent.prototype.freeBrowser));
});

it('should free browser with force after error in test', () => {
it('should invalidate session after error in test', () => {
CaptureSession.prototype.runActions.returns(q.reject());

return run_()
.catch(() => {
assert.calledWith(BrowserAgent.prototype.freeBrowser, sinon.match.any, {force: true});
assert.called(BrowserAgent.prototype.invalidateSession);
});
});

it('should free browser without force after `NoRefImageError` in test', () => {
it('should not invalidate session after `NoRefImageError`', () => {
CaptureSession.prototype.runActions.returns(q.reject(new NoRefImageError()));

return run_()
.then(() => {
assert.calledWith(BrowserAgent.prototype.freeBrowser, sinon.match.any, {force: false});
assert.notCalled(BrowserAgent.prototype.invalidateSession);
});
});
});
Expand Down

0 comments on commit 511b5c9

Please sign in to comment.