Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4971c3b

Browse filesBrowse files
Trottaddaleax
authored andcommitted
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 <santiago.gimeno@gmail.com>
1 parent 6297b9a commit 4971c3b
Copy full SHA for 4971c3b

File tree

Expand file treeCollapse file tree

4 files changed

+56
-55
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+56
-55
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-dgram-empty-packet.js
-40Lines changed: 0 additions & 40 deletions
This file was deleted.
Collapse file
+11-5Lines changed: 11 additions & 5 deletions
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);
Collapse file
+11-10Lines changed: 11 additions & 10 deletions
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+
}));
Collapse file
+34Lines changed: 34 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.