Skip to content

Commit

Permalink
fix: fix error of executing end() multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
whxaxes committed Sep 8, 2017
1 parent 67eae6b commit dc5a8de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ module.exports = class TCPProxy extends EventEmitter {
}

end() {
if (!this.server) {
return Promise.resolve();
}

return new Promise(resolve => {
this.server.close(resolve);
});
Expand Down
8 changes: 8 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ describe('test/index.test.js', () => {
assert(response.data.toString() === `hello world ${data.port}`);
});

it('proxy should not throw error with executing end function multiple times', function* () {
data = yield createServer();
yield proxy.createProxy({ forwardPort: data.port });
yield proxy.end();
yield proxy.end();
yield proxy.end();
});

it('proxy should start only one server', done => {
co(function* () {
data = yield createServer();
Expand Down

0 comments on commit dc5a8de

Please sign in to comment.