smoke - mitigate #146785

This commit is contained in:
Benjamin Pasero 2022-04-05 18:03:36 +02:00
parent 6c7f263edb
commit 7c31267b20
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
2 changed files with 28 additions and 33 deletions

View file

@ -22,11 +22,7 @@ export interface ApplicationOptions extends LaunchOptions {
export class Application {
private static INSTANCES = 0;
constructor(private options: ApplicationOptions) {
Application.INSTANCES++;
this._userDataPath = options.userDataDir;
this._workspacePathOrFolder = options.workspacePath;
}
@ -88,17 +84,7 @@ export class Application {
const code = await this.startApplication(extraArgs);
// ...and make sure the window is ready to interact
const windowReady = measureAndLog(this.checkWindowReady(code), 'Application#checkWindowReady()', this.logger);
// Make sure to take a screenshot if waiting for window ready
// takes unusually long to help diagnose issues when Code does
// not seem to startup healthy.
const timeoutHandle = setTimeout(() => this.takeScreenshot(`checkWindowReady_instance_${Application.INSTANCES}`), 10000);
try {
await windowReady;
} finally {
clearTimeout(timeoutHandle);
}
await measureAndLog(this.checkWindowReady(code), 'Application#checkWindowReady()', this.logger);
}
async stop(): Promise<void> {
@ -119,15 +105,6 @@ export class Application {
await this._code?.stopTracing(name, persist);
}
private async takeScreenshot(name: string): Promise<void> {
const driver = this._code?.driver;
if (!(driver instanceof PlaywrightDriver)) {
return;
}
await driver.takeScreenshot(name);
}
private async startApplication(extraArgs: string[] = []): Promise<Code> {
const code = this._code = await launch({
...this.options,
@ -145,7 +122,7 @@ export class Application {
await code.waitForWindowIds(ids => ids.length > 0);
// We need a rendered workbench
await measureAndLog(code.waitForElement('.monaco-workbench', undefined, 300 /* 30s of retry */), 'Application#checkWindowReady: wait for .monaco-workbench element', this.logger);
await this.checkWorkbenchReady(code);
// Remote but not web: wait for a remote connection state change
if (this.remote) {
@ -164,4 +141,28 @@ export class Application {
}, 300 /* = 30s of retry */), 'Application#checkWindowReady: wait for remote indicator', this.logger);
}
}
private async checkWorkbenchReady(code: Code): Promise<void> {
const driver = code.driver;
// Web / Legacy: just poll for workbench element
if (this.web || !(driver instanceof PlaywrightDriver)) {
await measureAndLog(code.waitForElement('.monaco-workbench'), 'Application#checkWindowReady: wait for .monaco-workbench element', this.logger);
}
// Desktop (playwright): we see hangs, where IPC messages
// are not delivered (https://github.com/microsoft/vscode/issues/146785)
// Workaround is to try to reload the window when that happens
else {
try {
await measureAndLog(code.waitForElement('.monaco-workbench', undefined, 100 /* 10s of retry */), 'Application#checkWindowReady: wait for .monaco-workbench element', this.logger);
} catch (error) {
this.logger.log(`checkWindowReady: giving up after 10s, reloading window and trying again...`);
await driver.reload();
return this.checkWorkbenchReady(code);
}
}
}
}

View file

@ -77,14 +77,8 @@ export class PlaywrightDriver implements IDriver {
}
}
async takeScreenshot(name: string): Promise<void> {
try {
const persistPath = join(this.options.logsPath, `playwright-screenshot-${PlaywrightDriver.traceCounter++}-${name.replace(/\s+/g, '-')}.png`);
await measureAndLog(this.page.screenshot({ path: persistPath, type: 'png' }), 'takeScreenshot', this.options.logger);
} catch (error) {
// Ignore
}
async reload() {
await this.page.reload();
}
async exitApplication() {