mirror of
https://github.com/nodejs/node.git
synced 2025-05-21 08:57:07 +00:00

This helps to prevent issues where a failed test can keep a bound socket open long enough to cause other tests to fail with EADDRINUSE because the same port number is used. PR-URL: https://github.com/nodejs/node/pull/7045 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
31 lines
733 B
JavaScript
31 lines
733 B
JavaScript
'use strict';
|
|
require('../common');
|
|
var assert = require('assert');
|
|
var dgram = require('dgram');
|
|
|
|
var source = dgram.createSocket('udp4');
|
|
var target = dgram.createSocket('udp4');
|
|
var messages = 0;
|
|
|
|
process.on('exit', function() {
|
|
assert.equal(messages, 2);
|
|
});
|
|
|
|
target.on('message', function(buf) {
|
|
if (buf.toString() === 'abc') ++messages;
|
|
if (buf.toString() === 'def') ++messages;
|
|
if (messages === 2) {
|
|
source.close();
|
|
target.close();
|
|
}
|
|
});
|
|
|
|
target.on('listening', function() {
|
|
// Second .send() call should not throw a bind error.
|
|
const port = this.address().port;
|
|
source.send(Buffer.from('abc'), 0, 3, port, '127.0.0.1');
|
|
source.send(Buffer.from('def'), 0, 3, port, '127.0.0.1');
|
|
});
|
|
|
|
target.bind(0);
|