| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent be241c3 commit 01f010f
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,20 +11,26 @@ const toSend = [Buffer.alloc(256, 'x'), | |||
| 11 | 11 | Buffer.alloc(256, 'z'), | |
| 12 | 12 | 'hello']; | |
| 13 | 13 | ||
| 14 | - client.on('listening', function() { | ||
| 14 | + const received = []; | ||
| 15 | + | ||
| 16 | + client.on('listening', common.mustCall(() => { | ||
| 15 | 17 | client.send(toSend[0], 0, toSend[0].length, common.PORT); | |
| 16 | 18 | client.send(toSend[1], common.PORT); | |
| 17 | 19 | client.send([toSend[2]], common.PORT); | |
| 18 | 20 | client.send(toSend[3], 0, toSend[3].length, common.PORT); | |
| 19 | - }); | ||
| 21 | + })); | ||
| 22 | + | ||
| 23 | + client.on('message', common.mustCall((buf, info) => { | ||
| 24 | + received.push(buf.toString()); | ||
| 20 | 25 | ||
| 21 | - client.on('message', function(buf, info) { | ||
| 22 | - const expected = toSend.shift().toString(); | ||
| 23 | - assert.ok(buf.toString() === expected, 'message was received correctly'); | ||
| 26 | + if (received.length === toSend.length) { | ||
| 27 | + // The replies may arrive out of order -> sort them before checking. | ||
| 28 | + received.sort(); | ||
| 24 | 29 | ||
| 25 | - if (toSend.length === 0) { | ||
| 30 | + const expected = toSend.map(String).sort(); | ||
| 31 | + assert.deepStrictEqual(received, expected); | ||
| 26 | 32 | client.close(); | |
| 27 | 33 | } | |
| 28 | - }); | ||
| 34 | + }, toSend.length)); | ||
| 29 | 35 | ||
| 30 | 36 | client.bind(common.PORT); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,26 +11,31 @@ if (!common.hasIPv6) { | |||
| 11 | 11 | ||
| 12 | 12 | const client = dgram.createSocket('udp6'); | |
| 13 | 13 | ||
| 14 | - const toSend = [new Buffer(256), new Buffer(256), new Buffer(256), 'hello']; | ||
| 14 | + const toSend = [Buffer.alloc(256, 'x'), | ||
| 15 | + Buffer.alloc(256, 'y'), | ||
| 16 | + Buffer.alloc(256, 'z'), | ||
| 17 | + 'hello']; | ||
| 15 | 18 | ||
| 16 | - toSend[0].fill('x'); | ||
| 17 | - toSend[1].fill('y'); | ||
| 18 | - toSend[2].fill('z'); | ||
| 19 | + const received = []; | ||
| 19 | 20 | ||
| 20 | - client.on('listening', function() { | ||
| 21 | + client.on('listening', common.mustCall(() => { | ||
| 21 | 22 | client.send(toSend[0], 0, toSend[0].length, common.PORT); | |
| 22 | 23 | client.send(toSend[1], common.PORT); | |
| 23 | 24 | client.send([toSend[2]], common.PORT); | |
| 24 | 25 | client.send(toSend[3], 0, toSend[3].length, common.PORT); | |
| 25 | - }); | ||
| 26 | + })); | ||
| 26 | 27 | ||
| 27 | - client.on('message', function(buf, info) { | ||
| 28 | - const expected = toSend.shift().toString(); | ||
| 29 | - assert.ok(buf.toString() === expected, 'message was received correctly'); | ||
| 28 | + client.on('message', common.mustCall((buf, info) => { | ||
| 29 | + received.push(buf.toString()); | ||
| 30 | 30 | ||
| 31 | - if (toSend.length === 0) { | ||
| 31 | + if (received.length === toSend.length) { | ||
| 32 | + // The replies may arrive out of order -> sort them before checking. | ||
| 33 | + received.sort(); | ||
| 34 | + | ||
| 35 | + const expected = toSend.map(String).sort(); | ||
| 36 | + assert.deepStrictEqual(received, expected); | ||
| 32 | 37 | client.close(); | |
| 33 | 38 | } | |
| 34 | - }); | ||
| 39 | + }, toSend.length)); | ||
| 35 | 40 | ||
| 36 | 41 | client.bind(common.PORT); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments