Skip to content

Commit

Permalink
Fix browser restart (closes DevExpress#3781) (DevExpress#3809)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev authored and kirovboris committed Dec 18, 2019
1 parent 2a06b39 commit 4a59ef0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
48 changes: 38 additions & 10 deletions src/browser/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class BrowserConnection extends EventEmitter {
this.jobQueue = [];
this.initScriptsQueue = [];
this.browserConnectionGateway = gateway;
this.errorSuppressed = false;
this.disconnectionPromise = null;
this.testRunAborted = false;

this.browserInfo = browserInfo;
Expand Down Expand Up @@ -120,15 +120,12 @@ export default class BrowserConnection extends EventEmitter {
this.heartbeatTimeout = setTimeout(() => {
const err = this._createBrowserDisconnectedError();

this.opened = false;
this.errorSuppressed = false;
this.testRunAborted = true;
this.opened = false;
this.testRunAborted = true;

this.emit('disconnected', err);

if (!this.errorSuppressed)
this.emit('error', err);

this._restartBrowserOnDisconnect(err);
}, this.HEARTBEAT_TIMEOUT);
}

Expand All @@ -150,7 +147,7 @@ export default class BrowserConnection extends EventEmitter {
return connections[id] || null;
}

async restartBrowser () {
async _restartBrowser () {
this.ready = false;

this._forceIdle();
Expand Down Expand Up @@ -183,8 +180,39 @@ export default class BrowserConnection extends EventEmitter {
});
}

suppressError () {
this.errorSuppressed = true;
_restartBrowserOnDisconnect (err) {
let resolveFn = null;
let rejectFn = null;

this.disconnectionPromise = new Promise((resolve, reject) => {
resolveFn = resolve;

rejectFn = () => {
reject(err);
};

setTimeout(() => {
rejectFn();
});
})
.then(() => {
return this._restartBrowser();
})
.catch(e => {
this.emit('error', e);
});

this.disconnectionPromise.resolve = resolveFn;
this.disconnectionPromise.reject = rejectFn;
}

async processDisconnection (disconnectionThresholdExceedeed) {
const { resolve, reject } = this.disconnectionPromise;

if (disconnectionThresholdExceedeed)
reject();
else
resolve();
}

addWarning (...args) {
Expand Down
14 changes: 7 additions & 7 deletions src/runner/test-run-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ export default class TestRunController extends AsyncEventEmitter {
await this.emit('test-run-before-done');
}

async _testRunDisconnected (connection) {
_testRunDisconnected (connection) {
this.disconnectionCount++;

if (this.disconnectionCount < DISCONNECT_THRESHOLD) {
connection.suppressError();
const disconnectionThresholdExceedeed = this.disconnectionCount >= DISCONNECT_THRESHOLD;

await connection.restartBrowser();

await this._restartTest();
}
return connection
.processDisconnection(disconnectionThresholdExceedeed)
.then(() => {
return this._restartTest();
});
}

get blocked () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ function run (pathToTest, filter) {
});
}

// NOTE: don't work on TravisCI, fix it ASAP
describe.skip('Browser reconnect', function () {
describe('Browser reconnect', function () {
if (config.useLocalBrowsers) {
it('Should restart browser when it does not respond', function () {
return run('./testcafe-fixtures/index-test.js', 'Should restart browser when it does not respond', { only: 'chrome' })
Expand Down

0 comments on commit 4a59ef0

Please sign in to comment.