From 7a0fecc0a739032cb35e4982bc5d8787b870e7cf Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Wed, 6 Sep 2023 09:36:50 +0200 Subject: [PATCH 1/4] #191860 - retry if command is not found --- test/automation/src/code.ts | 4 ++ test/automation/src/quickaccess.ts | 44 ++++++++++++++++--- .../src/areas/extensions/extensions.test.ts | 2 +- .../src/areas/workbench/localization.test.ts | 2 +- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/test/automation/src/code.ts b/test/automation/src/code.ts index e8ad52540b5..4d0a74da4a8 100644 --- a/test/automation/src/code.ts +++ b/test/automation/src/code.ts @@ -254,6 +254,10 @@ export class Code { return this.driver.getLogs(); } + wait(millis: number): Promise { + return new Promise((resolve, reject) => setTimeout(resolve, millis)); + } + private async poll( fn: () => Promise, acceptFn: (result: T) => boolean, diff --git a/test/automation/src/quickaccess.ts b/test/automation/src/quickaccess.ts index 116f58b7747..a04ee52395c 100644 --- a/test/automation/src/quickaccess.ts +++ b/test/automation/src/quickaccess.ts @@ -171,15 +171,47 @@ export class QuickAccess { } async runCommand(commandId: string, keepOpen?: boolean): Promise { + let retries = 0; + let error; - // open commands picker - await this.openQuickAccessWithRetry(QuickAccessKind.Commands, `>${commandId}`); + while (true) { - // wait for best choice to be focused - await this.quickInput.waitForQuickInputElementFocused(); + if (++retries > 5) { + throw error ?? new Error(`Command: ${commandId} Not found`); + } + + // open commands picker + await this.openQuickAccessWithRetry(QuickAccessKind.Commands, `>${commandId}`); + + // wait for best choice to be focused + await this.quickInput.waitForQuickInputElementFocused(); + + // Retry for as long as the command not found + const text = await this.quickInput.waitForQuickInputElementText(); + if (text === 'No matching commands') { + this.code.logger.log(`QuickAccess: No matching commands, will retry...`); + await this.quickInput.closeQuickInput(); + await this.code.wait(1000); + continue; + } + + try { + // wait and click on best choice + await this.quickInput.selectQuickInputElement(0, keepOpen); + } catch (err) { + if (keepOpen) { + throw err; + } else { + error = err; + this.code.logger.log(`QuickAccess: Probably no matching commands, will retry...`); + await this.quickInput.closeQuickInput(); + continue; + } + } + + break; + } - // wait and click on best choice - await this.quickInput.selectQuickInputElement(0, keepOpen); } async openQuickOutline(): Promise { diff --git a/test/smoke/src/areas/extensions/extensions.test.ts b/test/smoke/src/areas/extensions/extensions.test.ts index bc65a8631c4..c78cbe87089 100644 --- a/test/smoke/src/areas/extensions/extensions.test.ts +++ b/test/smoke/src/areas/extensions/extensions.test.ts @@ -7,7 +7,7 @@ import { Application, Logger } from '../../../../automation'; import { installAllHandlers } from '../../utils'; export function setup(logger: Logger) { - describe.skip('Extensions', () => { + describe('Extensions', () => { // Shared before/after handling installAllHandlers(logger); diff --git a/test/smoke/src/areas/workbench/localization.test.ts b/test/smoke/src/areas/workbench/localization.test.ts index 865add9ae79..12e49ce549e 100644 --- a/test/smoke/src/areas/workbench/localization.test.ts +++ b/test/smoke/src/areas/workbench/localization.test.ts @@ -8,7 +8,7 @@ import { installAllHandlers } from '../../utils'; export function setup(logger: Logger) { - describe.skip('Localization', () => { + describe('Localization', () => { // Shared before/after handling installAllHandlers(logger); From 6e93ce037bb242119c9ccb8f43ae999bfb37ca7b Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Wed, 6 Sep 2023 10:30:13 +0200 Subject: [PATCH 2/4] feedback --- test/automation/src/code.ts | 6 +++--- test/automation/src/playwrightDriver.ts | 6 +++--- test/automation/src/terminal.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/automation/src/code.ts b/test/automation/src/code.ts index 4d0a74da4a8..1647e78640b 100644 --- a/test/automation/src/code.ts +++ b/test/automation/src/code.ts @@ -185,7 +185,7 @@ export class Code { try { process.kill(pid, 0); // throws an exception if the process doesn't exist anymore. - await new Promise(resolve => setTimeout(resolve, 500)); + await this.wait(500); } catch (error) { done = true; resolve(); @@ -255,7 +255,7 @@ export class Code { } wait(millis: number): Promise { - return new Promise((resolve, reject) => setTimeout(resolve, millis)); + return this.driver.wait(millis); } private async poll( @@ -289,7 +289,7 @@ export class Code { lastError = Array.isArray(e.stack) ? e.stack.join(os.EOL) : e.stack; } - await new Promise(resolve => setTimeout(resolve, retryInterval)); + await this.wait(retryInterval); trial++; } } diff --git a/test/automation/src/playwrightDriver.ts b/test/automation/src/playwrightDriver.ts index 1b63f622f4e..ddc99579fdf 100644 --- a/test/automation/src/playwrightDriver.ts +++ b/test/automation/src/playwrightDriver.ts @@ -157,7 +157,7 @@ export class PlaywrightDriver { for (let i = 0; i < chords.length; i++) { const chord = chords[i]; if (i > 0) { - await this.timeout(100); + await this.wait(100); } if (keybinding.startsWith('Alt') || keybinding.startsWith('Control') || keybinding.startsWith('Backspace')) { @@ -179,7 +179,7 @@ export class PlaywrightDriver { } } - await this.timeout(100); + await this.wait(100); } async click(selector: string, xoffset?: number | undefined, yoffset?: number | undefined) { @@ -235,7 +235,7 @@ export class PlaywrightDriver { return this.page.evaluate(pageFunction, [await this.getDriverHandle()]); } - private timeout(ms: number): Promise { + wait(ms: number): Promise { return new Promise(resolve => setTimeout(resolve, ms)); } diff --git a/test/automation/src/terminal.ts b/test/automation/src/terminal.ts index 56b6f46ddb4..e0604a5b45f 100644 --- a/test/automation/src/terminal.ts +++ b/test/automation/src/terminal.ts @@ -99,7 +99,7 @@ export class Terminal { // after 2 seconds. await Promise.race([ this.code.waitForElements(Selector.Xterm, true, e => e.length === 0), - new Promise(r => setTimeout(r, 2000)) + this.code.wait(2000) ]); break; } From 7b15902db0038e96bda37b9ff5e0347e05d707da Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Wed, 6 Sep 2023 10:58:27 +0200 Subject: [PATCH 3/4] only check for No matching commands text --- test/automation/src/quickaccess.ts | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/test/automation/src/quickaccess.ts b/test/automation/src/quickaccess.ts index a04ee52395c..67b4a6ad289 100644 --- a/test/automation/src/quickaccess.ts +++ b/test/automation/src/quickaccess.ts @@ -172,13 +172,8 @@ export class QuickAccess { async runCommand(commandId: string, keepOpen?: boolean): Promise { let retries = 0; - let error; - while (true) { - - if (++retries > 5) { - throw error ?? new Error(`Command: ${commandId} Not found`); - } + while (++retries > 5) { // open commands picker await this.openQuickAccessWithRetry(QuickAccessKind.Commands, `>${commandId}`); @@ -195,23 +190,14 @@ export class QuickAccess { continue; } - try { - // wait and click on best choice - await this.quickInput.selectQuickInputElement(0, keepOpen); - } catch (err) { - if (keepOpen) { - throw err; - } else { - error = err; - this.code.logger.log(`QuickAccess: Probably no matching commands, will retry...`); - await this.quickInput.closeQuickInput(); - continue; - } - } + // wait and click on best choice + await this.quickInput.selectQuickInputElement(0, keepOpen); - break; + return; } + throw new Error(`Command: ${commandId} Not found`); + } async openQuickOutline(): Promise { From 9ed384ffe76b139f65a50c111fbbd5cfb947b73b Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Wed, 6 Sep 2023 11:10:35 +0200 Subject: [PATCH 4/4] fix while check --- test/automation/src/quickaccess.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/automation/src/quickaccess.ts b/test/automation/src/quickaccess.ts index 67b4a6ad289..4c0f1079db1 100644 --- a/test/automation/src/quickaccess.ts +++ b/test/automation/src/quickaccess.ts @@ -173,7 +173,7 @@ export class QuickAccess { async runCommand(commandId: string, keepOpen?: boolean): Promise { let retries = 0; - while (++retries > 5) { + while (++retries < 5) { // open commands picker await this.openQuickAccessWithRetry(QuickAccessKind.Commands, `>${commandId}`);