chore: calcular pool digests on the loader process side (#20728)

This commit is contained in:
Pavel Feldman 2023-02-07 14:08:17 -08:00 committed by GitHub
parent b67cef2c4d
commit 96f0674e41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 20 deletions

View File

@ -21,10 +21,12 @@ import type { FullConfigInternal } from '../common/types';
import { loadTestFile } from '../common/testLoader';
import type { TestError } from '../../reporter';
import { addToCompilationCache, serializeCompilationCache } from '../common/compilationCache';
import { PoolBuilder } from '../common/poolBuilder';
export class LoaderMain extends ProcessRunner {
private _serializedConfig: SerializedConfig;
private _configPromise: Promise<FullConfigInternal> | undefined;
private _poolBuilder = PoolBuilder.createForLoader();
constructor(serializedConfig: SerializedConfig) {
super();
@ -42,6 +44,7 @@ export class LoaderMain extends ProcessRunner {
const testErrors: TestError[] = [];
const config = await this._config();
const fileSuite = await loadTestFile(params.file, config.rootDir, testErrors);
this._poolBuilder.buildPools(fileSuite);
return { fileSuite: fileSuite._deepSerialize(), testErrors };
}

View File

@ -17,7 +17,6 @@
import path from 'path';
import type { Reporter, TestError } from '../../types/testReporter';
import { InProcessLoaderHost, OutOfProcessLoaderHost } from './loaderHost';
import type { LoaderHost } from './loaderHost';
import { Suite } from '../common/test';
import type { TestCase } from '../common/test';
import type { FullConfigInternal, FullProjectInternal } from '../common/types';
@ -81,7 +80,7 @@ export async function loadAllTests(mode: 'out-of-process' | 'in-process', config
// Load all test files and create a preprocessed root. Child suites are files there.
const fileSuits: Suite[] = [];
{
const loaderHost: LoaderHost = mode === 'out-of-process' ? new OutOfProcessLoaderHost(config) : new InProcessLoaderHost(config);
const loaderHost = mode === 'out-of-process' ? new OutOfProcessLoaderHost(config) : new InProcessLoaderHost(config);
const allTestFiles = new Set<string>();
for (const files of filesToRunByProject.values())
files.forEach(file => allTestFiles.add(file));

View File

@ -19,13 +19,12 @@ import { serializeConfig } from '../common/ipc';
import { ProcessHost } from './processHost';
import { Suite } from '../common/test';
import { loadTestFile } from '../common/testLoader';
import type { LoadError } from '../common/fixtures';
import type { FullConfigInternal } from '../common/types';
import { PoolBuilder } from '../common/poolBuilder';
import { addToCompilationCache } from '../common/compilationCache';
export abstract class LoaderHost {
protected _config: FullConfigInternal;
export class InProcessLoaderHost {
private _config: FullConfigInternal;
private _poolBuilder: PoolBuilder;
constructor(config: FullConfigInternal) {
@ -34,41 +33,31 @@ export abstract class LoaderHost {
}
async loadTestFile(file: string, testErrors: TestError[]): Promise<Suite> {
const result = await this.doLoadTestFile(file, testErrors);
const result = await loadTestFile(file, this._config.rootDir, testErrors);
this._poolBuilder.buildPools(result, testErrors);
return result;
}
protected abstract doLoadTestFile(file: string, testErrors: TestError[]): Promise<Suite>;
async stop() {}
}
export class InProcessLoaderHost extends LoaderHost {
doLoadTestFile(file: string, testErrors: TestError[]): Promise<Suite> {
return loadTestFile(file, this._config.rootDir, testErrors);
}
}
export class OutOfProcessLoaderHost extends LoaderHost {
export class OutOfProcessLoaderHost {
private _startPromise: Promise<void>;
private _processHost: ProcessHost;
constructor(config: FullConfigInternal) {
super(config);
this._processHost = new ProcessHost(require.resolve('../loader/loaderMain.js'), 'loader');
this._startPromise = this._processHost.startRunner(serializeConfig(config), true, {});
}
async doLoadTestFile(file: string, loadErrors: LoadError[]): Promise<Suite> {
async loadTestFile(file: string, testErrors: TestError[]): Promise<Suite> {
await this._startPromise;
const result = await this._processHost.sendMessage({ method: 'loadTestFile', params: { file } }) as any;
loadErrors.push(...result.testErrors);
testErrors.push(...result.testErrors);
return Suite._deepParse(result.fileSuite);
}
override async stop() {
async stop() {
await this._startPromise;
const result = await this._processHost.sendMessage({ method: 'serializeCompilationCache' }) as any;
addToCompilationCache(result);