Files
node/test/parallel/test-dgram-bind-shared-ports.js
T
Fikret Burak Gazioglu 0bfd103480 test: refactor test-dgram-bind-shared-ports.js
Refactored the code to latest standards, where all var is
changed to const, functions are changed to arrow functions
and assert.equal chaned to assert.strictEqual

PR-URL: https://github.com/nodejs/node/pull/8582
Reviewed-By: Robert Jefe Lindstaedt <robert.lindstaedt@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
2016-09-21 02:52:59 +03:00

57 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const dgram = require('dgram');
function noop() { }
if (cluster.isMaster) {
const worker1 = cluster.fork();
if (common.isWindows) {
const checkErrType = (er) => {
assert.strictEqual(er.code, 'ENOTSUP');
worker1.kill();
};
worker1.on('error', common.mustCall(checkErrType, 1));
return;
}
worker1.on('message', (msg) => {
assert.strictEqual(msg, 'success');
const worker2 = cluster.fork();
worker2.on('message', (msg) => {
assert.strictEqual(msg, 'socket2:EADDRINUSE');
worker1.kill();
worker2.kill();
});
});
} else {
const socket1 = dgram.createSocket('udp4', noop);
const socket2 = dgram.createSocket('udp4', noop);
socket1.on('error', (err) => {
// no errors expected
process.send('socket1:' + err.code);
});
socket2.on('error', (err) => {
// an error is expected on the second worker
process.send('socket2:' + err.code);
});
socket1.bind({
address: 'localhost',
port: common.PORT,
exclusive: false
}, () => {
socket2.bind({ port: common.PORT + 1, exclusive: true }, () => {
// the first worker should succeed
process.send('success');
});
});
}