From 6c3bb99c634567da3db3ff9cccecc506a79a36e3 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 5 Aug 2021 09:05:17 +0200 Subject: [PATCH] smoke - better exit application handling --- src/vs/platform/driver/common/driver.ts | 2 +- src/vs/platform/driver/electron-main/driver.ts | 8 +++----- src/vs/platform/driver/node/driver.ts | 2 +- test/automation/src/code.ts | 5 ++++- test/automation/src/playwrightDriver.ts | 9 ++++++++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/vs/platform/driver/common/driver.ts b/src/vs/platform/driver/common/driver.ts index 8974a3baaed..e447cee2532 100644 --- a/src/vs/platform/driver/common/driver.ts +++ b/src/vs/platform/driver/common/driver.ts @@ -42,7 +42,7 @@ export interface IDriver { getWindowIds(): Promise; capturePage(windowId: number): Promise; reloadWindow(windowId: number): Promise; - exitApplication(): Promise; + exitApplication(): Promise; dispatchKeybinding(windowId: number, keybinding: string): Promise; click(windowId: number, selector: string, xoffset?: number | undefined, yoffset?: number | undefined): Promise; doubleClick(windowId: number, selector: string): Promise; diff --git a/src/vs/platform/driver/electron-main/driver.ts b/src/vs/platform/driver/electron-main/driver.ts index ed0376899d4..187cb4de27e 100644 --- a/src/vs/platform/driver/electron-main/driver.ts +++ b/src/vs/platform/driver/electron-main/driver.ts @@ -20,7 +20,6 @@ import { KeybindingParser } from 'vs/base/common/keybindingParser'; import { timeout } from 'vs/base/common/async'; import { IDriver, IDriverOptions, IElement, ILocaleInfo, ILocalizedStrings, IWindowDriver, IWindowDriverRegistry } from 'vs/platform/driver/common/driver'; import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService'; -import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeHostMainService'; function isSilentKeyCode(keyCode: KeyCode) { return keyCode < KeyCode.KEY_0; @@ -38,8 +37,7 @@ export class Driver implements IDriver, IWindowDriverRegistry { private windowServer: IPCServer, private options: IDriverOptions, @IWindowsMainService private readonly windowsMainService: IWindowsMainService, - @ILifecycleMainService private readonly lifecycleMainService: ILifecycleMainService, - @INativeHostMainService private readonly nativeHostMainService: INativeHostMainService + @ILifecycleMainService private readonly lifecycleMainService: ILifecycleMainService ) { } async registerWindowDriver(windowId: number): Promise { @@ -82,8 +80,8 @@ export class Driver implements IDriver, IWindowDriverRegistry { this.lifecycleMainService.reload(window); } - async exitApplication(): Promise { - return this.nativeHostMainService.quit(undefined); + exitApplication(): Promise { + return this.lifecycleMainService.quit(); } async dispatchKeybinding(windowId: number, keybinding: string): Promise { diff --git a/src/vs/platform/driver/node/driver.ts b/src/vs/platform/driver/node/driver.ts index 26ff75b2c0d..111c4d86349 100644 --- a/src/vs/platform/driver/node/driver.ts +++ b/src/vs/platform/driver/node/driver.ts @@ -60,7 +60,7 @@ export class DriverChannelClient implements IDriver { return this.channel.call('reloadWindow', windowId); } - exitApplication(): Promise { + exitApplication(): Promise { return this.channel.call('exitApplication'); } diff --git a/test/automation/src/code.ts b/test/automation/src/code.ts index 2137186895c..8b43e2cfa5e 100644 --- a/test/automation/src/code.ts +++ b/test/automation/src/code.ts @@ -294,7 +294,10 @@ export class Code { } async exit(): Promise { - await this.driver.exitApplication(); + const success = await this.driver.exitApplication(); + if (success === false) { + throw new Error('Code exit was blocked by a veto.'); + } } async waitForTextContent(selector: string, textContent?: string, accept?: (result: string) => boolean, retryCount?: number): Promise { diff --git a/test/automation/src/playwrightDriver.ts b/test/automation/src/playwrightDriver.ts index fee0705e3b8..26dee587e33 100644 --- a/test/automation/src/playwrightDriver.ts +++ b/test/automation/src/playwrightDriver.ts @@ -50,6 +50,8 @@ function buildDriver(browser: playwright.Browser, context: playwright.BrowserCon console.error(error); // do not fail the build when this fails } await teardown(); + + return true; }, dispatchKeybinding: async (windowId, keybinding) => { const chords = keybinding.split(' '); @@ -202,7 +204,12 @@ export function connect(options: Options = {}): Promise<{ client: IDisposable, d const payloadParam = `[["enableProposedApi",""],["skipWelcome","true"]]`; await page.goto(`${endpoint}&folder=vscode-remote://localhost:9888${URI.file(workspacePath!).path}&payload=${payloadParam}`); const result = { - client: { dispose: () => browser.close() && teardown() }, + client: { + dispose: () => { + browser.close(); + teardown(); + } + }, driver: buildDriver(browser, context, page) }; c(result);