Skip to content

Commit 75bebbf

Browse 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 <[email protected]>
1 parent 1296a68 commit 75bebbf

File tree

4 files changed

+56
-55
lines changed

4 files changed

+56
-55
lines changed

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

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
'use strict';
22

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

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

10+
constassert=require('assert');
11+
constdgram=require('dgram');
12+
1213
constclient=dgram.createSocket('udp4');
1314

15+
varinterval;
16+
1417
client.on('message',common.mustCall(functiononMessage(buf,info){
1518
constexpected=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);
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
'use strict';
22
constcommon=require('../common');
3-
constdgram=require('dgram');
3+
constassert=require('assert');
44

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

10+
constdgram=require('dgram');
11+
1012
constclient=dgram.createSocket('udp4');
1113

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

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

2023
constbuf=Buffer.alloc(0);
21-
client.send(buf,0,0,port,'127.0.0.1',function(err,len){});
22-
23-
consttimer=setTimeout(function(){
24-
thrownewError('Timeout');
25-
},common.platformTimeout(200));
26-
});
24+
varinterval=setInterval(function(){
25+
client.send(buf,0,0,port,'127.0.0.1',common.mustCall(function(){}));
26+
},10);
27+
}));
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
constassert=require('assert');
4+
5+
if(common.isOSX){
6+
common.skip('because of 17894467 Apple bug');
7+
return;
8+
}
9+
10+
constdgram=require('dgram');
11+
12+
constclient=dgram.createSocket('udp4');
13+
14+
client.bind(0,common.mustCall(function(){
15+
16+
client.on('message',common.mustCall(callback));
17+
18+
constport=this.address().port;
19+
constbuf=Buffer.alloc(1);
20+
21+
constinterval=setInterval(function(){
22+
client.send(buf,0,0,port,'127.0.0.1',common.mustCall(callback));
23+
},10);
24+
25+
functioncallback(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(firstArginstanceofBuffer){
29+
assert.strictEqual(firstArg.length,0);
30+
clearInterval(interval);
31+
client.close();
32+
}
33+
}
34+
}));

0 commit comments

Comments
(0)