2023-01-17 12:43:51 -08:00
|
|
|
/**
|
|
|
|
* Copyright Microsoft Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import type { TestGroup } from './dispatcher';
|
2023-01-17 17:38:44 -08:00
|
|
|
import type { RunPayload, SerializedLoaderData, WorkerInitParams } from './ipc';
|
2023-01-17 12:43:51 -08:00
|
|
|
import { ProcessHost } from './processHost';
|
|
|
|
|
|
|
|
let lastWorkerIndex = 0;
|
|
|
|
|
|
|
|
export class WorkerHost extends ProcessHost<WorkerInitParams> {
|
|
|
|
readonly parallelIndex: number;
|
|
|
|
readonly workerIndex: number;
|
|
|
|
private _hash: string;
|
|
|
|
currentTestId: string | null = null;
|
2023-01-17 14:53:11 -08:00
|
|
|
private _params: WorkerInitParams;
|
2023-01-17 12:43:51 -08:00
|
|
|
|
2023-01-17 17:38:44 -08:00
|
|
|
constructor(testGroup: TestGroup, parallelIndex: number, loader: SerializedLoaderData) {
|
2023-01-17 14:53:11 -08:00
|
|
|
const workerIndex = lastWorkerIndex++;
|
|
|
|
super(require.resolve('./workerRunner.js'), `worker-${workerIndex}`);
|
|
|
|
this.workerIndex = workerIndex;
|
2023-01-17 12:43:51 -08:00
|
|
|
this.parallelIndex = parallelIndex;
|
|
|
|
this._hash = testGroup.workerHash;
|
|
|
|
|
2023-01-17 14:53:11 -08:00
|
|
|
this._params = {
|
2023-01-17 12:43:51 -08:00
|
|
|
workerIndex: this.workerIndex,
|
|
|
|
parallelIndex,
|
|
|
|
repeatEachIndex: testGroup.repeatEachIndex,
|
|
|
|
projectId: testGroup.projectId,
|
|
|
|
loader,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-01-17 14:53:11 -08:00
|
|
|
async start() {
|
|
|
|
await this.startRunner(this._params);
|
2023-01-17 12:43:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
runTestGroup(runPayload: RunPayload) {
|
|
|
|
this.sendMessageNoReply({ method: 'runTestGroup', params: runPayload });
|
|
|
|
}
|
|
|
|
|
|
|
|
hash() {
|
|
|
|
return this._hash;
|
|
|
|
}
|
|
|
|
}
|