Skip to content

Commit

Permalink
fix: fixed start test before task starting finishes (#7102)
Browse files Browse the repository at this point in the history
* test: added test Should not start any test before report task start finishes

* fix: fixed start test before task starting finishes

* fix: fixes based on comments
  • Loading branch information
Aleksey28 committed Jun 23, 2022
1 parent 992a1bf commit 73f6c2d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/runner/browser-job.ts
Expand Up @@ -20,8 +20,10 @@ interface BrowserJobResultInfo {
data?: any; // eslint-disable-line @typescript-eslint/no-explicit-any
}

enum BrowserJobStatus { initialized, starting, started }

export default class BrowserJob extends AsyncEventEmitter {
private _started: boolean;
private _status: BrowserJobStatus;
private _startTime: Date;
private _total: number;
private _passed: number;
Expand Down Expand Up @@ -53,7 +55,7 @@ export default class BrowserJob extends AsyncEventEmitter {
}: BrowserJobInit) {
super();

this._started = false;
this._status = BrowserJobStatus.initialized;
this._startTime = new Date();

this._total = 0;
Expand Down Expand Up @@ -170,6 +172,11 @@ export default class BrowserJob extends AsyncEventEmitter {
}

private async _isNextTestRunAvailable (testRunController: TestRunController): Promise<boolean> {
// NOTE: event task start is currently executing,
// so test run is temporary blocked
if (this._status === BrowserJobStatus.starting)
return false;

// NOTE: before hook for test run fixture is currently
// executing, so test run is temporary blocked
const isBlocked = testRunController.blocked;
Expand Down Expand Up @@ -213,11 +220,13 @@ export default class BrowserJob extends AsyncEventEmitter {
this._testRunControllerQueue.shift();
this._addToCompletionQueue(testRunController);

if (!this._started) {
this._started = true;
this._startTime = new Date();
if (this._status === BrowserJobStatus.initialized) {
this._status = BrowserJobStatus.starting;
this._startTime = new Date();

await this.emit('start', this._startTime);

this._status = BrowserJobStatus.started;
}

const testRunUrl = await testRunController.start(connection, this._startTime);
Expand Down
24 changes: 24 additions & 0 deletions test/functional/fixtures/concurrency/test.js
Expand Up @@ -77,6 +77,17 @@ if (config.useLocalBrowsers) {
},
});

const slowReporter = createReporter({
reportTaskStart: async function () {
await new Promise(resolve => setTimeout(() => resolve(), 100));
this.write('Task start').newline();
},

reportTestStart: async function () {
this.write('Test start').newline();
},
});

beforeEach(function () {
data = '';
});
Expand Down Expand Up @@ -138,6 +149,19 @@ if (config.useLocalBrowsers) {
});
});

it('Should not start any test before report task start finishes', function () {
return run('chrome:headless --no-sandbox', 2, './testcafe-fixtures/concurrent-test.js', slowReporter)
.then(failedCount => {
expect(failedCount).eql(0);
expect(data.split('\n')).eql([
'Task start',
'Test start',
'Test start',
'',
]);
});
});

it('Should fail if number of remotes is not divisible by concurrency', function () {
return createConnections(3)
.then(function (connections) {
Expand Down

0 comments on commit 73f6c2d

Please sign in to comment.