node/test/parallel/test-cluster-dgram-reuse.js
Jeremiah Senkpiel 52bae222a3 test: abstract skip functionality to common
The tap skipping output is so prevalent yet obscure in nature that we
ought to move it into it's own function in test/common.js

PR-URL: https://github.com/nodejs/node/pull/6697
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2016-05-12 16:43:35 -04:00

41 lines
857 B
JavaScript

'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().on('exit', function(code) {
assert.equal(code, 0);
});
return;
}
const sockets = [];
function next() {
sockets.push(this);
if (sockets.length !== 2)
return;
// Work around health check issue
process.nextTick(function() {
for (var i = 0; i < sockets.length; i++)
sockets[i].close(close);
});
}
var waiting = 2;
function close() {
if (--waiting === 0)
cluster.worker.disconnect();
}
for (var i = 0; i < 2; i++)
dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(common.PORT, next);