Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed start test before task starting finishes #7102

Merged
merged 3 commits into from Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 StartStatus { none, starting, started }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum BrowserJobStatus { initialized, starting, started }


export default class BrowserJob extends AsyncEventEmitter {
private _started: boolean;
private _startStatus: StartStatus;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private _status:...

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._startStatus = StartStatus.none;
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._startStatus === StartStatus.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._startStatus === StartStatus.none) {
this._startStatus = StartStatus.starting;
this._startTime = new Date();

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

this._startStatus = StartStatus.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