node/test/parallel/test-dgram-udp6-send-default-host.js
Anna Henningsen aa34b43909
test: allow out-of-order replies in dgram tests
Allow out of order replies in the flaky
`test-dgram{-upd6,}-send-default-host.js` files by sorting
the incoming replies after receiving them.

PR-URL: https://github.com/nodejs/node/pull/6607
Fixes: https://github.com/nodejs/node/issues/6577
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2016-05-10 07:56:52 +02:00

42 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
if (!common.hasIPv6) {
console.log('1..0 # Skipped: no IPv6 support');
return;
}
const client = dgram.createSocket('udp6');
const toSend = [Buffer.alloc(256, 'x'),
Buffer.alloc(256, 'y'),
Buffer.alloc(256, 'z'),
'hello'];
const received = [];
client.on('listening', common.mustCall(() => {
client.send(toSend[0], 0, toSend[0].length, common.PORT);
client.send(toSend[1], common.PORT);
client.send([toSend[2]], common.PORT);
client.send(toSend[3], 0, toSend[3].length, common.PORT);
}));
client.on('message', common.mustCall((buf, info) => {
received.push(buf.toString());
if (received.length === toSend.length) {
// The replies may arrive out of order -> sort them before checking.
received.sort();
const expected = toSend.map(String).sort();
assert.deepStrictEqual(received, expected);
client.close();
}
}, toSend.length));
client.bind(common.PORT);