node/test/parallel/test-cluster-dgram-reuse.js
Vse Mozhet Byt 2d2986ae72 test: simplify test skipping
* Make common.skip() exit.

  Also add common.printSkipMessage() for partial skips.

* Don't make needless things before skip

PR-URL: https://github.com/nodejs/node/pull/14021
Fixes: https://github.com/nodejs/node/issues/14016
Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-07-04 12:41:49 +03:00

36 lines
833 B
JavaScript

'use strict';
const common = require('../common');
if (common.isWindows)
common.skip('dgram clustering is currently not supported on windows.');
const assert = require('assert');
const cluster = require('cluster');
const dgram = require('dgram');
if (cluster.isMaster) {
cluster.fork().on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
return;
}
let waiting = 2;
function close() {
if (--waiting === 0)
cluster.worker.disconnect();
}
const options = { type: 'udp4', reuseAddr: true };
const socket1 = dgram.createSocket(options);
const socket2 = dgram.createSocket(options);
socket1.bind(0, () => {
socket2.bind(socket1.address().port, () => {
// Work around health check issue
process.nextTick(() => {
socket1.close(close);
socket2.close(close);
});
});
});