Skip to content

Commit 9b0f53d

Browse files
committed
test: fix flaky test-dgram-empty-packet & friends
* Liberal use of common.mustCall() * Rename test-dgram-empty-packet -> test-dgram-send-empty-packet * Remove use of timers to avoid CI failures like seen in the Ref below: ``` not ok 237 parallel/test-dgram-empty-packet --- duration_ms: 0.717 severity: fail stack: |- ... throw new Error('Timeout'); ^ Error: Timeout at Timeout._onTimeout ... at ontimeout (timers.js:365:14) at tryOnTimeout (timers.js:237:5) at Timer.listOnTimeout (timers.js:207:5) ``` Refs: https://ci.nodejs.org/job/node-test-commit-freebsd/5341/nodes=freebsd11-x64/console: PR-URL: #9724 Reviewed-By: Santiago Gimeno <[email protected]>
1 parent 7e6fcf3 commit 9b0f53d

4 files changed

+56
-55
lines changed

test/parallel/test-dgram-empty-packet.js

-40
This file was deleted.
+11-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
'use strict';
22

33
const common = require('../common');
4-
const assert = require('assert');
5-
const dgram = require('dgram');
64

75
if (common.isOSX) {
86
common.skip('because of 17894467 Apple bug');
97
return;
108
}
119

10+
const assert = require('assert');
11+
const dgram = require('dgram');
12+
1213
const client = dgram.createSocket('udp4');
1314

15+
var interval;
16+
1417
client.on('message', common.mustCall(function onMessage(buf, info) {
1518
const expected = Buffer.alloc(0);
1619
assert.ok(buf.equals(expected), 'message was received correctly');
20+
clearInterval(interval);
1721
client.close();
1822
}));
1923

20-
client.on('listening', function() {
21-
client.send([], this.address().port, common.localhostIPv4);
22-
});
24+
client.on('listening', common.mustCall(function() {
25+
interval = setInterval(function() {
26+
client.send([], client.address().port, common.localhostIPv4);
27+
}, 10);
28+
}));
2329

2430
client.bind(0);
+11-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
'use strict';
22
const common = require('../common');
3-
const dgram = require('dgram');
3+
const assert = require('assert');
44

55
if (common.isOSX) {
66
common.skip('because of 17894467 Apple bug');
77
return;
88
}
99

10+
const dgram = require('dgram');
11+
1012
const client = dgram.createSocket('udp4');
1113

12-
client.bind(0, function() {
14+
client.bind(0, common.mustCall(function() {
1315
const port = this.address().port;
1416

15-
client.on('message', common.mustCall(function onMessage(buffer, bytes) {
16-
clearTimeout(timer);
17+
client.on('message', common.mustCall(function onMessage(buffer) {
18+
assert.strictEqual(buffer.length, 0);
19+
clearInterval(interval);
1720
client.close();
1821
}));
1922

2023
const buf = Buffer.alloc(0);
21-
client.send(buf, 0, 0, port, '127.0.0.1', function(err, len) { });
22-
23-
const timer = setTimeout(function() {
24-
throw new Error('Timeout');
25-
}, common.platformTimeout(200));
26-
});
24+
var interval = setInterval(function() {
25+
client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall(function() {}));
26+
}, 10);
27+
}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
5+
if (common.isOSX) {
6+
common.skip('because of 17894467 Apple bug');
7+
return;
8+
}
9+
10+
const dgram = require('dgram');
11+
12+
const client = dgram.createSocket('udp4');
13+
14+
client.bind(0, common.mustCall(function() {
15+
16+
client.on('message', common.mustCall(callback));
17+
18+
const port = this.address().port;
19+
const buf = Buffer.alloc(1);
20+
21+
const interval = setInterval(function() {
22+
client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall(callback));
23+
}, 10);
24+
25+
function callback(firstArg) {
26+
// If client.send() callback, firstArg should be null.
27+
// If client.on('message') listener, firstArg should be a 0-length buffer.
28+
if (firstArg instanceof Buffer) {
29+
assert.strictEqual(firstArg.length, 0);
30+
clearInterval(interval);
31+
client.close();
32+
}
33+
}
34+
}));

0 commit comments

Comments
 (0)