smoke - support retryWithRestart in web too

This commit is contained in:
Benjamin Pasero 2022-04-19 09:03:17 +02:00
parent 24273bd759
commit a9010d094a
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
3 changed files with 10 additions and 5 deletions

View file

@ -6,8 +6,7 @@
import * as playwright from '@playwright/test';
import { ChildProcess, spawn } from 'child_process';
import { join } from 'path';
import { mkdir } from 'fs';
import { promisify } from 'util';
import * as mkdirp from 'mkdirp';
import { URI } from 'vscode-uri';
import { Logger, measureAndLog } from './logger';
import type { LaunchOptions } from './code';
@ -35,7 +34,7 @@ async function launchServer(options: LaunchOptions) {
const { userDataDir, codePath, extensionsPath, logger, logsPath } = options;
const codeServerPath = codePath ?? process.env.VSCODE_REMOTE_SERVER_PATH;
const agentFolder = userDataDir;
await measureAndLog(promisify(mkdir)(agentFolder), `mkdir(${agentFolder})`, logger);
await measureAndLog(mkdirp(agentFolder), `mkdirp(${agentFolder})`, logger);
const env = {
VSCODE_REMOTE_SERVER_PATH: codeServerPath,

View file

@ -107,7 +107,7 @@ const testDataPath = path.join(os.tmpdir(), 'vscsmoke');
if (fs.existsSync(testDataPath)) {
rimraf.sync(testDataPath);
}
fs.mkdirSync(testDataPath);
mkdirp.sync(testDataPath);
process.once('exit', () => {
try {
rimraf.sync(testDataPath);

View file

@ -150,9 +150,13 @@ export function timeout(i: number) {
}
export async function retryWithRestart(app: Application, testFn: () => Promise<unknown>, retries = 3, timeoutMs = 20000): Promise<unknown> {
let lastError: Error | undefined = undefined;
for (let i = 0; i < retries; i++) {
const result = await Promise.race([
testFn().then(() => true, error => { throw error; }),
testFn().then(() => true, error => {
lastError = error;
return false;
}),
timeout(timeoutMs).then(() => false)
]);
@ -162,6 +166,8 @@ export async function retryWithRestart(app: Application, testFn: () => Promise<u
await app.restart();
}
throw lastError ?? new Error('retryWithRestart failed with an unknown error');
}
export interface ITask<T> {