Skip to content

Commit

Permalink
test: increase coverage of internal/socket_list
Browse files Browse the repository at this point in the history
PR-URL: #12066
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
DavidCai1111 authored and jasnell committed Apr 4, 2017
1 parent 085c1f8 commit 610ac7d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/parallel/test-internal-socket-list-receive.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const key = 'test-key';

const list = new SocketListReceive(child, key);
list.child.emit('internalMessage', { key, cmd: 'NODE_SOCKET_NOTIFY_CLOSE' });
list.child.emit('internalMessage', { key, cmd: 'NODE_SOCKET_GET_COUNT' });
}

// Verify that a "NODE_SOCKET_ALL_CLOSED" message will be sent.
Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-internal-socket-list-send.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,25 @@ const key = 'test-key';
assert.strictEqual(child.listenerCount('disconnect'), 0);
}));
}

// Verify that an error will be received in callback when child is
// disconnected after sending a message and before getting the reply.
{
const count = 1;
const child = Object.assign(new EventEmitter(), {
connected: true,
send: function(msg) {
process.nextTick(() => {
this.emit('disconnect');
this.emit('internalMessage', { key, count, cmd: 'NODE_SOCKET_COUNT' });
});
}
});

const list = new SocketListSend(child, key);

list.getConnections(common.mustCall((err, msg) => {
assert.strictEqual(err.message, 'child closed before reply');
assert.strictEqual(child.listenerCount('internalMessage'), 0);
}));
}

0 comments on commit 610ac7d

Please sign in to comment.