Skip to content

Commit

Permalink
work around edge invoke hanging on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
feil0n9wan9 committed Mar 13, 2019
1 parent 88e5e8c commit 8a9e638
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
17 changes: 11 additions & 6 deletions lib/edge/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions test/edge/container.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
};
},
Expand Down

0 comments on commit 8a9e638

Please sign in to comment.