From 5940231b7633e891cd765b80cea343d7502cf37f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 25 Sep 2017 10:49:54 +0900 Subject: [PATCH 1/2] spec: Do not assume which process exits first in singleton test --- spec/api-app-spec.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 035520bb414c..8a2062d78c8f 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -162,19 +162,23 @@ describe('app module', function () { this.timeout(120000) const appPath = path.join(__dirname, 'fixtures', 'api', 'singleton') // First launch should exit with 0. - let secondLaunched = false + let exited = 0 const first = ChildProcess.spawn(remote.process.execPath, [appPath]) first.once('exit', (code) => { - assert.ok(secondLaunched) assert.equal(code, 0) - done() + exited++ + if (exited === 2) { + done() + } }) // Second launch should exit with 1. const second = ChildProcess.spawn(remote.process.execPath, [appPath]) second.once('exit', (code) => { - assert.ok(!secondLaunched) assert.equal(code, 1) - secondLaunched = true + exited++ + if (exited === 2) { + done() + } }) }) }) From d87ea5713d66a3cd669c2e7a940c3993ca2b841f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 25 Sep 2017 11:19:25 +0900 Subject: [PATCH 2/2] spec: It is not certain which process starts first --- spec/api-app-spec.js | 19 +++++++------------ spec/fixtures/api/singleton/main.js | 4 +--- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 8a2062d78c8f..58925deca48b 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -162,23 +162,18 @@ describe('app module', function () { this.timeout(120000) const appPath = path.join(__dirname, 'fixtures', 'api', 'singleton') // First launch should exit with 0. - let exited = 0 const first = ChildProcess.spawn(remote.process.execPath, [appPath]) first.once('exit', (code) => { assert.equal(code, 0) - exited++ - if (exited === 2) { - done() - } }) - // Second launch should exit with 1. - const second = ChildProcess.spawn(remote.process.execPath, [appPath]) - second.once('exit', (code) => { - assert.equal(code, 1) - exited++ - if (exited === 2) { + // Start second app when received output. + first.stdout.once('data', () => { + // Second launch should exit with 1. + const second = ChildProcess.spawn(remote.process.execPath, [appPath]) + second.once('exit', (code) => { + assert.equal(code, 1) done() - } + }) }) }) }) diff --git a/spec/fixtures/api/singleton/main.js b/spec/fixtures/api/singleton/main.js index 1cf75c4a6646..07176e0097ef 100644 --- a/spec/fixtures/api/singleton/main.js +++ b/spec/fixtures/api/singleton/main.js @@ -1,8 +1,6 @@ const {app} = require('electron') -process.on('uncaughtException', () => { - app.exit(2) -}) +console.log('started') // ping parent const shouldExit = app.makeSingleInstance(() => { process.nextTick(() => app.exit(0))