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 8872840

Browse filesBrowse files
santigimenomcollina
authored andcommitted
test: refactor test-dgram-send-callback-recursive
Just send 10 messages recursively and check that the send calls are asynchronous by asserting that a `setImmediate` callback has been called in-between. It avoids a race condition in the test when the recursive limit is reached without having received at least 10 messages. Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> PR-URL: #5079
1 parent dff01d1 commit 8872840
Copy full SHA for 8872840

File tree

Expand file treeCollapse file tree

1 file changed

+10
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-8
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-dgram-send-callback-recursive.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-dgram-send-callback-recursive.js
+10-8Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@ const assert = require('assert');
55
const dgram = require('dgram');
66
const client = dgram.createSocket('udp4');
77
const chunk = 'abc';
8-
var recursiveCount = 0;
9-
var received = 0;
8+
let received = 0;
9+
let sent = 0;
1010
const limit = 10;
11-
const recursiveLimit = 100;
11+
let async = false;
1212

1313
function onsend() {
14-
if (recursiveCount > recursiveLimit) {
15-
throw new Error('infinite loop detected');
16-
}
17-
if (received < limit) {
14+
if (sent++ < limit) {
1815
client.send(
1916
chunk, 0, chunk.length, common.PORT, common.localhostIPv4, onsend);
17+
} else {
18+
assert.strictEqual(async, true, 'Send should be asynchronous.');
2019
}
21-
recursiveCount++;
2220
}
2321

2422
client.on('listening', function() {
23+
setImmediate(function() {
24+
async = true;
25+
});
26+
2527
onsend();
2628
});
2729

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.