Skip to content

Commit

Permalink
tests: fix event race condition in test streaming destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed May 13, 2015
1 parent a783de6 commit 59cd7e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/FakeServer.js
Expand Up @@ -340,6 +340,7 @@ FakeConnection.prototype._writePacketStream = function _writePacketStream(count)
var timer = setInterval(writeRow.bind(this), 20);

this._socket.on('close', cleanup);
this._socket.on('error', cleanup);

this._sendPacket(new Packets.ResultSetHeaderPacket({
fieldCount: 2
Expand All @@ -366,6 +367,7 @@ FakeConnection.prototype._writePacketStream = function _writePacketStream(count)
function cleanup() {
var socket = this._socket || this;
socket.removeListener('close', cleanup);
socket.removeListener('error', cleanup);
clearInterval(timer);
}

Expand Down
5 changes: 4 additions & 1 deletion test/unit/query/test-streaming-destroy.js
Expand Up @@ -14,6 +14,9 @@ server.listen(common.fakeServerPort, function (err) {
count++;
assert.equal(count, 1);
connection.destroy();
server.destroy();

process.nextTick(function () {
server.destroy();
});
});
});

0 comments on commit 59cd7e9

Please sign in to comment.