From 8a9e6388abde22a8a04dbccbc5cb32a10b784c3d Mon Sep 17 00:00:00 2001 From: Feilong Wang Date: Tue, 12 Mar 2019 21:33:07 +0800 Subject: [PATCH] work around edge invoke hanging on Windows --- lib/edge/container.js | 17 +++++++++++------ test/edge/container.test.js | 20 ++++++++++---------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/edge/container.js b/lib/edge/container.js index 08fe6902f..45fa0340d 100644 --- a/lib/edge/container.js +++ b/lib/edge/container.js @@ -197,13 +197,18 @@ class Container { AttachStderr: true, Tty: true, }); - const stream = await exec.start({hijack: true}); await new Promise((resolve, reject) => { - stream.output.on('end', () => { - resolve(); - }); - stream.output.on('error', (err) => { - reject(err); + exec.start({hijack: true}, (err, stream) => { + stream.on('end', () => { + resolve(); + }); + stream.on('error', (err) => { + reject(err); + }); + // FIXME There is no 'end' event being received on windows. Send one manually. + if (process.platform === 'win32') { + setTimeout(() => stream.end(), 0); + } }); }); // Copy to the target path. diff --git a/test/edge/container.test.js b/test/edge/container.test.js index f2d09311f..a431c7381 100644 --- a/test/edge/container.test.js +++ b/test/edge/container.test.js @@ -4,6 +4,7 @@ const expect = require('expect.js'); const sinon = require('sinon'); const Docker = require('dockerode'); const inquirer = require('inquirer'); +const EventEmitter = require('events'); const Container = require('../../lib/edge/container'); const TEST_CONTAINER_ID = 'd852359721fe'; @@ -394,16 +395,15 @@ describe('edge/Container', function () { const getContainer = sinon.stub(docker, 'getContainer').returns({ exec: async function () { return { - start: async function () { - return { - output: { - on: function (event, handler) { - if (event === 'end') { - handler(); - } - } - }, - }; + start: function (opts, callback) { + class Stream extends EventEmitter { + end() { + this.emit('end'); + } + } + const stream = new Stream(); + setTimeout(() => stream.end(), 0); + callback(null, stream); } }; },