smoke - strengthen shutdown path

This commit is contained in:
Benjamin Pasero 2021-11-26 18:08:23 +01:00
parent e2adc711f3
commit df4b5d6d04
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
2 changed files with 15 additions and 12 deletions

View file

@ -63,7 +63,7 @@ function getBuildOutPath(root: string): string {
} }
} }
async function connect(connectDriver: typeof connectElectronDriver, child: cp.ChildProcess | undefined, outPath: string, handlePath: string, logger: Logger): Promise<Code> { async function connect(connectDriver: typeof connectElectronDriver | typeof connectPlaywrightDriver, child: cp.ChildProcess | undefined, outPath: string, handlePath: string, logger: Logger): Promise<Code> {
let errCount = 0; let errCount = 0;
while (true) { while (true) {
@ -79,7 +79,7 @@ async function connect(connectDriver: typeof connectElectronDriver, child: cp.Ch
} }
// retry // retry
await new Promise(c => setTimeout(c, 100)); await new Promise(resolve => setTimeout(resolve, 100));
} }
} }
} }
@ -116,14 +116,12 @@ export async function spawn(options: SpawnOptions): Promise<Code> {
const handle = await createDriverHandle(); const handle = await createDriverHandle();
let child: cp.ChildProcess | undefined; let child: cp.ChildProcess | undefined;
let connectDriver: typeof connectElectronDriver;
copyExtension(options.extensionsPath, 'vscode-notebook-tests'); copyExtension(options.extensionsPath, 'vscode-notebook-tests');
if (options.web) { if (options.web) {
await launch(options.userDataDir, options.workspacePath, options.codePath, options.extensionsPath, Boolean(options.verbose)); await launch(options.userDataDir, options.workspacePath, options.codePath, options.extensionsPath, Boolean(options.verbose));
connectDriver = connectPlaywrightDriver.bind(connectPlaywrightDriver, options); return connect(connectPlaywrightDriver.bind(connectPlaywrightDriver, options), child, '', handle, options.logger);
return connect(connectDriver, child, '', handle, options.logger);
} }
const env = { ...process.env }; const env = { ...process.env };
@ -199,8 +197,7 @@ export async function spawn(options: SpawnOptions): Promise<Code> {
child = cp.spawn(electronPath, args, spawnOptions); child = cp.spawn(electronPath, args, spawnOptions);
instances.add(child); instances.add(child);
child.once('exit', () => instances.delete(child!)); child.once('exit', () => instances.delete(child!));
connectDriver = connectElectronDriver; return connect(connectElectronDriver, child, outPath, handle, options.logger);
return connect(connectDriver, child, outPath, handle, options.logger);
} }
async function copyExtension(extensionsPath: string, extId: string): Promise<void> { async function copyExtension(extensionsPath: string, extId: string): Promise<void> {

View file

@ -57,9 +57,15 @@ class PlaywrightDriver implements IDriver {
try { try {
await this._context.tracing.stop({ path: join(logsPath, `playwright-trace-${traceCounter++}.zip`) }); await this._context.tracing.stop({ path: join(logsPath, `playwright-trace-${traceCounter++}.zip`) });
} catch (error) { } catch (error) {
console.warn(`Failed to stop playwright tracing.`); // do not fail the build when this fails console.warn(`Failed to stop playwright tracing: ${error}`);
} }
await this._browser.close();
try {
await this._browser.close();
} catch (error) {
console.warn(`Failed to close browser: ${error}`);
}
await teardown(); await teardown();
return false; return false;
@ -207,9 +213,9 @@ export async function launch(userDataDir: string, _workspacePath: string, codeSe
async function teardown(): Promise<void> { async function teardown(): Promise<void> {
if (server) { if (server) {
try { try {
await new Promise<void>((c, e) => kill(server!.pid, err => err ? e(err) : c())); await new Promise<void>((resolve, reject) => kill(server!.pid, err => err ? reject(err) : resolve()));
} catch { } catch (error) {
// noop console.warn(`Error tearing down server: ${error}`);
} }
server = undefined; server = undefined;