summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2017-02-10 11:41:32 -0500
committercjihrig <cjihrig@gmail.com>2017-02-14 11:54:06 -0500
commitac602a251a0ca385775a71357d52e9c752430dfb (patch)
tree83707d968f5fd16a85825e64cfe445948017fff4 /test
parent784eb2fd65ab0e17f3ec15b801c8e9d78866681a (diff)
downloadandroid-node-v8-ac602a251a0ca385775a71357d52e9c752430dfb.tar.gz
android-node-v8-ac602a251a0ca385775a71357d52e9c752430dfb.tar.bz2
android-node-v8-ac602a251a0ca385775a71357d52e9c752430dfb.zip
test: cover dgram socket close during cluster bind
When a non-exclusive dgram socket is bound from a cluster worker, it attempts to get a handle from the cluster module. This commit adds coverage for the case where the socket is closed while querying the cluster module for a handle. PR-URL: https://github.com/nodejs/node/pull/11292 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-dgram-cluster-close-during-bind.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/parallel/test-dgram-cluster-close-during-bind.js b/test/parallel/test-dgram-cluster-close-during-bind.js
new file mode 100644
index 0000000000..ec62693abf
--- /dev/null
+++ b/test/parallel/test-dgram-cluster-close-during-bind.js
@@ -0,0 +1,40 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const cluster = require('cluster');
+const dgram = require('dgram');
+
+if (common.isWindows) {
+ common.skip('dgram clustering is currently not supported on windows.');
+ return;
+}
+
+if (cluster.isMaster) {
+ cluster.fork();
+} else {
+ // When the socket attempts to bind, it requests a handle from the cluster.
+ // Close the socket before returning the handle from the cluster.
+ const socket = dgram.createSocket('udp4');
+ const _getServer = cluster._getServer;
+
+ cluster._getServer = common.mustCall(function(self, options, callback) {
+ socket.close(common.mustCall(() => {
+ _getServer.call(this, self, options, common.mustCall((err, handle) => {
+ assert.strictEqual(err, 0);
+
+ // When the socket determines that it was already closed, it will
+ // close the handle. Use handle.close() to terminate the test.
+ const close = handle.close;
+
+ handle.close = common.mustCall(function() {
+ setImmediate(() => cluster.worker.disconnect());
+ return close.call(this);
+ });
+
+ callback(err, handle);
+ }));
+ }));
+ });
+
+ socket.bind(common.mustNotCall('Socket should not bind.'));
+}