Skip to content

Commit 68eb974

Browse files
cjihrigitaloacasas
authored andcommitted
test: cover cluster error during dgram socket bind
When a non-exclusive dgram socket is bound from a cluster worker, a handle is requested from the cluster module. This commit adds coverage for the case where an error occurs while retrieving the handle. PR-URL: nodejs#11295 Reviewed-By: James M Snell <[email protected]>
1 parent 2952512 commit 68eb974

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cluster = require('cluster');
5+
const dgram = require('dgram');
6+
const { UV_UNKNOWN } = process.binding('uv');
7+
8+
if (cluster.isMaster) {
9+
cluster.fork();
10+
} else {
11+
// When the socket attempts to bind, it requests a handle from the cluster.
12+
// Force the cluster to send back an error code.
13+
cluster._getServer = function(self, options, callback) {
14+
callback(UV_UNKNOWN);
15+
};
16+
17+
const socket = dgram.createSocket('udp4');
18+
19+
socket.on('error', common.mustCall((err) => {
20+
assert(/^Error: bind UNKNOWN 0.0.0.0$/.test(err.toString()));
21+
process.nextTick(common.mustCall(() => {
22+
assert.strictEqual(socket._bindState, 0); // BIND_STATE_UNBOUND
23+
socket.close();
24+
cluster.worker.disconnect();
25+
}));
26+
}));
27+
28+
socket.bind(common.mustNotCall('Socket should not bind.'));
29+
}

0 commit comments

Comments
 (0)