mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix: wait for worker to be ready before initializing (#13270)
fix: wait for worker to be ready before initializing The test dispatcher waits until a worker is ready before sending the `init` message. This guarantees that the worker process is listening for the message. Otherwise, the worker process might miss the `init` message and the subsequent `run` message would crash the worker.
This commit is contained in:
parent
4e1fb1728f
commit
3e65ef35cf
@ -466,6 +466,7 @@ class Worker extends EventEmitter {
|
|||||||
private _didSendStop = false;
|
private _didSendStop = false;
|
||||||
private _didFail = false;
|
private _didFail = false;
|
||||||
private didExit = false;
|
private didExit = false;
|
||||||
|
private _ready: Promise<void>;
|
||||||
|
|
||||||
constructor(hash: string, parallelIndex: number) {
|
constructor(hash: string, parallelIndex: number) {
|
||||||
super();
|
super();
|
||||||
@ -494,9 +495,15 @@ class Worker extends EventEmitter {
|
|||||||
const { method, params } = message;
|
const { method, params } = message;
|
||||||
this.emit(method, params);
|
this.emit(method, params);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._ready = new Promise((resolve, reject) => {
|
||||||
|
this.process.once('exit', () => reject(new Error('worker exited before it became ready')));
|
||||||
|
this.once('ready', () => resolve());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(testGroup: TestGroup, loaderData: SerializedLoaderData) {
|
async init(testGroup: TestGroup, loaderData: SerializedLoaderData) {
|
||||||
|
await this._ready;
|
||||||
const params: WorkerInitParams = {
|
const params: WorkerInitParams = {
|
||||||
workerIndex: this.workerIndex,
|
workerIndex: this.workerIndex,
|
||||||
parallelIndex: this.parallelIndex,
|
parallelIndex: this.parallelIndex,
|
||||||
@ -505,7 +512,6 @@ class Worker extends EventEmitter {
|
|||||||
loader: loaderData,
|
loader: loaderData,
|
||||||
};
|
};
|
||||||
this.send({ method: 'init', params });
|
this.send({ method: 'init', params });
|
||||||
await new Promise(f => this.process.once('message', f)); // Ready ack
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run(testGroup: TestGroup) {
|
run(testGroup: TestGroup) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user