Skip to content

Commit

Permalink
refactor and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed May 21, 2019
1 parent fa8bdd1 commit 7bfc324
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
27 changes: 21 additions & 6 deletions src/browser/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,37 @@ export default class BrowserConnection extends EventEmitter {

_restartBrowserOnDisconnect (err) {
let resolveFn = null;
let rejectFn = null;

this.disconnectionPromise = new Promise(resolve => {
this.disconnectionPromise = new Promise((resolve, reject) => {
resolveFn = resolve;
})
.then(disconnectionThresholdExceedeed => {
if (disconnectionThresholdExceedeed)
this.emit('error', err);

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) {
this.disconnectionPromise.resolve(disconnectionThresholdExceedeed);
const { resolve, reject } = this.disconnectionPromise;

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

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

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

const disconnectionThresholdExceedeed = this.disconnectionCount >= DISCONNECT_THRESHOLD;

await connection.processDisconnection(disconnectionThresholdExceedeed);

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

get blocked () {
Expand Down

0 comments on commit 7bfc324

Please sign in to comment.