From af0cc2ee2303ece9a6414309f69283d825ea63aa Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Fri, 15 Sep 2017 12:54:11 +0200 Subject: [PATCH] smoke: omg, they were all using the same port! --- test/smoke/package.json | 1 + test/smoke/src/spectron/application.ts | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/test/smoke/package.json b/test/smoke/package.json index 1ab31447938..99c529813c7 100644 --- a/test/smoke/package.json +++ b/test/smoke/package.json @@ -19,6 +19,7 @@ "htmlparser2": "^3.9.2", "mocha": "^3.2.0", "ncp": "^2.0.0", + "portastic": "^1.0.1", "rimraf": "^2.6.1", "spectron": "~3.6.4", "strip-json-comments": "^2.0.1", diff --git a/test/smoke/src/spectron/application.ts b/test/smoke/src/spectron/application.ts index ea6fb20ed16..e4dfb9932fc 100644 --- a/test/smoke/src/spectron/application.ts +++ b/test/smoke/src/spectron/application.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Application, SpectronClient as WebClient } from 'spectron'; +import { test as testPort } from 'portastic'; import { SpectronClient } from './client'; import { ScreenCapturer } from '../helpers/screenshot'; import { Workbench } from '../areas/workbench/workbench'; @@ -26,6 +27,18 @@ export enum VSCODE_BUILD { STABLE } +async function findFreePort(): Promise { + for (let i = 0; i < 10; i++) { + const port = 10000 + Math.round(Math.random() * 5000); + + if (await testPort(port)) { + return port; + } + } + + throw new Error('Could not find free port!'); +} + /** * Wraps Spectron's Application instance with its used methods. */ @@ -116,8 +129,15 @@ export class SpectronApplication { chromeDriverArgs.push(`--user-data-dir=${path.join(this._userDir, new Date().getTime().toString())}`); + // Spectron always uses the same port number for the chrome driver + // and it handles gracefully when two instances use the same port number + // This works, but when one of the instances quits, it takes down + // chrome driver with it, leaving the other instance in DISPAIR!!! :( + const port = await findFreePort(); + this.spectron = new Application({ path: this._electronPath, + port, args, chromeDriverArgs, startTimeout: 10000, @@ -135,7 +155,7 @@ export class SpectronApplication { // Spectron opens multiple terminals in Windows platform // Workaround to focus the right window - https://github.com/electron/spectron/issues/60 await this.client.windowByIndex(1); - await this.app.browserWindow.focus(); + // await this.app.browserWindow.focus(); await this.client.waitForHTML('[id="workbench.main.container"]'); }