Skip to content

Commit

Permalink
ensure driver always gets info about testrun (>=FF58) (DevExpress#2105)
Browse files Browse the repository at this point in the history
* [WIP] ensure driver gets info about testrun

* remove FF57 fixation

* fix test-server 'Should provide status'

* remove extra line

* minor changes according to review
  • Loading branch information
AlexKamaev authored and AlexanderMoskovkin committed Feb 10, 2018
1 parent 78d40fc commit 6dc9023
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 58 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ install:
choco install GoogleChrome
choco install Firefox --version 57.0.1
choco install Firefox
- cmd: >-
node --version
Expand Down
11 changes: 10 additions & 1 deletion src/browser/connection/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class BrowserConnectionGateway {
this._dispatch('/browser/heartbeat/{id}', proxy, BrowserConnectionGateway.onHeartbeat);
this._dispatch('/browser/idle/{id}', proxy, BrowserConnectionGateway.onIdle);
this._dispatch('/browser/status/{id}', proxy, BrowserConnectionGateway.onStatusRequest);
this._dispatch('/browser/status-done/{id}', proxy, BrowserConnectionGateway.onStatusRequestOnTestDone);
this._dispatch('/browser/init-script/{id}', proxy, BrowserConnectionGateway.onInitScriptRequest);
this._dispatch('/browser/init-script/{id}', proxy, BrowserConnectionGateway.onInitScriptResponse, 'POST');

Expand Down Expand Up @@ -87,8 +88,16 @@ export default class BrowserConnectionGateway {
}

static async onStatusRequest (req, res, connection) {
return BrowserConnectionGateway._onStatusRequestCore(req, res, connection, false);
}

static async onStatusRequestOnTestDone (req, res, connection) {
return BrowserConnectionGateway._onStatusRequestCore(req, res, connection, true);
}

static async _onStatusRequestCore (req, res, connection, isTestDone) {
if (BrowserConnectionGateway.ensureConnectionReady(res, connection)) {
var status = await connection.getStatus();
var status = await connection.getStatus(isTestDone);

respondWithJSON(res, status);
}
Expand Down
36 changes: 20 additions & 16 deletions src/browser/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@ export default class BrowserConnection extends EventEmitter {

this.provider = browserInfo.provider;

this.permanent = permanent;
this.closing = false;
this.closed = false;
this.ready = false;
this.opened = false;
this.idle = true;
this.switchingToIdle = false;
this.heartbeatTimeout = null;
this.permanent = permanent;
this.closing = false;
this.closed = false;
this.ready = false;
this.opened = false;
this.idle = true;
this.heartbeatTimeout = null;
this.pendingTestRunUrl = null;

this.url = `${gateway.domain}/browser/connect/${this.id}`;
this.heartbeatUrl = `${gateway.domain}/browser/heartbeat/${this.id}`;
this.idleUrl = `${gateway.domain}/browser/idle/${this.id}`;
this.statusUrl = `${gateway.domain}/browser/status/${this.id}`;
this.statusDoneUrl = `${gateway.domain}/browser/status-done/${this.id}`;
this.initScriptUrl = `${gateway.domain}/browser/init-script/${this.id}`;

this.on('error', () => {
Expand Down Expand Up @@ -115,6 +116,13 @@ export default class BrowserConnection extends EventEmitter {
}, this.HEARTBEAT_TIMEOUT);
}

async _getTestRunUrl (isTestDone) {
if (isTestDone || !this.pendingTestRunUrl)
this.pendingTestRunUrl = await this._popNextTestRunUrl();

return this.pendingTestRunUrl;
}

async _popNextTestRunUrl () {
while (this.hasQueuedJobs && !this.currentJob.hasQueuedTestRuns)
this.jobQueue.shift();
Expand Down Expand Up @@ -230,25 +238,21 @@ export default class BrowserConnection extends EventEmitter {
await this.provider.reportJobResult(this.id, status, data);
}

async getStatus () {
if (this.switchingToIdle) {
this.switchingToIdle = false;
this.idle = true;
async getStatus (isTestDone) {
if (!this.idle && !isTestDone) {
this.idle = true;
this.emit('idle');
}

if (this.opened) {
var testRunUrl = await this._popNextTestRunUrl();
var testRunUrl = await this._getTestRunUrl(isTestDone);

if (testRunUrl) {
this.idle = false;
return { cmd: COMMAND.run, url: testRunUrl };
}
}

if (!this.idle)
this.switchingToIdle = true;

return { cmd: COMMAND.idle, url: this.idleUrl };
}
}
25 changes: 13 additions & 12 deletions src/client/driver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,18 @@ export default class Driver {
this.COMMAND_EXECUTING_FLAG = 'testcafe|driver|command-executing-flag';
this.EXECUTING_IN_IFRAME_FLAG = 'testcafe|driver|executing-in-iframe-flag';

this.testRunId = testRunId;
this.heartbeatUrl = communicationUrls.heartbeat;
this.browserStatusUrl = communicationUrls.status;
this.userAgent = runInfo.userAgent;
this.fixtureName = runInfo.fixtureName;
this.testName = runInfo.testName;
this.selectorTimeout = options.selectorTimeout;
this.pageLoadTimeout = options.pageLoadTimeout;
this.initialSpeed = options.speed;
this.skipJsErrors = options.skipJsErrors;
this.dialogHandler = options.dialogHandler;
this.testRunId = testRunId;
this.heartbeatUrl = communicationUrls.heartbeat;
this.browserStatusUrl = communicationUrls.status;
this.browserStatusDoneUrl = communicationUrls.statusDone;
this.userAgent = runInfo.userAgent;
this.fixtureName = runInfo.fixtureName;
this.testName = runInfo.testName;
this.selectorTimeout = options.selectorTimeout;
this.pageLoadTimeout = options.pageLoadTimeout;
this.initialSpeed = options.speed;
this.skipJsErrors = options.skipJsErrors;
this.dialogHandler = options.dialogHandler;

this.customCommandHandlers = {};

Expand Down Expand Up @@ -478,7 +479,7 @@ export default class Driver {

this
._sendStatus(status)
.then(() => browser.checkStatus(this.browserStatusUrl, hammerhead.createNativeXHR));
.then(() => browser.checkStatus(this.browserStatusDoneUrl, hammerhead.createNativeXHR));
}

_onBackupStoragesCommand () {
Expand Down
27 changes: 14 additions & 13 deletions src/client/test-run/index.js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
if (window !== window.top)
return;
var testRunId = {{{testRunId}}};
var browserId = {{{browserId}}};
var selectorTimeout = {{{selectorTimeout}}};
var pageLoadTimeout = {{{pageLoadTimeout}}};
var speed = {{{speed}}};
var browserHeartbeatUrl = {{{browserHeartbeatUrl}}};
var browserStatusUrl = {{{browserStatusUrl}}};
var skipJsErrors = {{{skipJsErrors}}};
var dialogHandler = {{{dialogHandler}}};
var userAgent = {{{userAgent}}};
var fixtureName = {{{fixtureName}}};
var testName = {{{testName}}};
var testRunId = {{{testRunId}}};
var browserId = {{{browserId}}};
var selectorTimeout = {{{selectorTimeout}}};
var pageLoadTimeout = {{{pageLoadTimeout}}};
var speed = {{{speed}}};
var browserHeartbeatUrl = {{{browserHeartbeatUrl}}};
var browserStatusUrl = {{{browserStatusUrl}}};
var browserStatusDoneUrl = {{{browserStatusDoneUrl}}};
var skipJsErrors = {{{skipJsErrors}}};
var dialogHandler = {{{dialogHandler}}};
var userAgent = {{{userAgent}}};
var fixtureName = {{{fixtureName}}};
var testName = {{{testName}}};

var ClientDriver = window['%testCafeDriver%'];
var driver = new ClientDriver(testRunId,
{ heartbeat: browserHeartbeatUrl, status: browserStatusUrl },
{ heartbeat: browserHeartbeatUrl, status: browserStatusUrl, statusDone: browserStatusDoneUrl },
{ userAgent: userAgent, fixtureName: fixtureName, testName: testName },
{
selectorTimeout: selectorTimeout,
Expand Down
25 changes: 13 additions & 12 deletions src/test-run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,19 @@ export default class TestRun extends Session {
this.resolveWaitForFileDownloadingPromise = null;

return Mustache.render(TEST_RUN_TEMPLATE, {
testRunId: JSON.stringify(this.id),
browserId: JSON.stringify(this.browserConnection.id),
browserHeartbeatUrl: JSON.stringify(this.browserConnection.heartbeatUrl),
browserStatusUrl: JSON.stringify(this.browserConnection.statusUrl),
userAgent: JSON.stringify(this.browserConnection.userAgent),
testName: JSON.stringify(this.test.name),
fixtureName: JSON.stringify(this.test.fixture.name),
selectorTimeout: this.opts.selectorTimeout,
pageLoadTimeout: this.pageLoadTimeout,
skipJsErrors: this.opts.skipJsErrors,
speed: this.speed,
dialogHandler: JSON.stringify(this.activeDialogHandler)
testRunId: JSON.stringify(this.id),
browserId: JSON.stringify(this.browserConnection.id),
browserHeartbeatUrl: JSON.stringify(this.browserConnection.heartbeatUrl),
browserStatusUrl: JSON.stringify(this.browserConnection.statusUrl),
browserStatusDoneUrl: JSON.stringify(this.browserConnection.statusDoneUrl),
userAgent: JSON.stringify(this.browserConnection.userAgent),
testName: JSON.stringify(this.test.name),
fixtureName: JSON.stringify(this.test.fixture.name),
selectorTimeout: this.opts.selectorTimeout,
pageLoadTimeout: this.pageLoadTimeout,
skipJsErrors: this.opts.skipJsErrors,
speed: this.speed,
dialogHandler: JSON.stringify(this.activeDialogHandler)
});
}

Expand Down
2 changes: 0 additions & 2 deletions test/functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ testingEnvironments[testingEnvironmentNames.osXDesktopAndMSEdgeBrowsers] = {
os: 'OS X',
osVersion: 'Sierra',
name: 'firefox',
version: '57.0',
alias: 'firefox-osx'
},
{
Expand Down Expand Up @@ -106,7 +105,6 @@ testingEnvironments[testingEnvironmentNames.localBrowsers] = {
{
platform: 'Windows 10',
browserName: 'firefox',
version: '57.0',
alias: 'firefox'
}
]
Expand Down
2 changes: 1 addition & 1 deletion test/server/browser-connection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('Browser connection', function () {
connection.addJob(createBrowserJobMock(['3']));

function queryStatus () {
return promisedRequest(connection.statusUrl);
return promisedRequest(connection.statusDoneUrl);
}

return promisedRequest(connection.url)
Expand Down

0 comments on commit 6dc9023

Please sign in to comment.