Skip to content

Commit

Permalink
test: fix flaky test-dgram-empty-packet & friends
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Trott committed Nov 24, 2016
1 parent 7e6fcf3 commit 9b0f53d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 55 deletions.
40 changes: 0 additions & 40 deletions test/parallel/test-dgram-empty-packet.js

This file was deleted.

16 changes: 11 additions & 5 deletions test/parallel/test-dgram-send-empty-array.js
Original file line number Original file line Diff line number Diff line change
@@ -1,24 +1,30 @@
'use strict'; 'use strict';


const common = require('../common'); const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');


if (common.isOSX) { if (common.isOSX) {
common.skip('because of 17894467 Apple bug'); common.skip('because of 17894467 Apple bug');
return; return;
} }


const assert = require('assert');
const dgram = require('dgram');

const client = dgram.createSocket('udp4'); const client = dgram.createSocket('udp4');


var interval;

client.on('message', common.mustCall(function onMessage(buf, info) { client.on('message', common.mustCall(function onMessage(buf, info) {
const expected = Buffer.alloc(0); const expected = Buffer.alloc(0);
assert.ok(buf.equals(expected), 'message was received correctly'); assert.ok(buf.equals(expected), 'message was received correctly');
clearInterval(interval);
client.close(); client.close();
})); }));


client.on('listening', function() { client.on('listening', common.mustCall(function() {
client.send([], this.address().port, common.localhostIPv4); interval = setInterval(function() {
}); client.send([], client.address().port, common.localhostIPv4);
}, 10);
}));


client.bind(0); client.bind(0);
21 changes: 11 additions & 10 deletions test/parallel/test-dgram-send-empty-buffer.js
Original file line number Original file line Diff line number Diff line change
@@ -1,26 +1,27 @@
'use strict'; 'use strict';
const common = require('../common'); const common = require('../common');
const dgram = require('dgram'); const assert = require('assert');


if (common.isOSX) { if (common.isOSX) {
common.skip('because of 17894467 Apple bug'); common.skip('because of 17894467 Apple bug');
return; return;
} }


const dgram = require('dgram');

const client = dgram.createSocket('udp4'); const client = dgram.createSocket('udp4');


client.bind(0, function() { client.bind(0, common.mustCall(function() {
const port = this.address().port; const port = this.address().port;


client.on('message', common.mustCall(function onMessage(buffer, bytes) { client.on('message', common.mustCall(function onMessage(buffer) {
clearTimeout(timer); assert.strictEqual(buffer.length, 0);
clearInterval(interval);
client.close(); client.close();
})); }));


const buf = Buffer.alloc(0); const buf = Buffer.alloc(0);
client.send(buf, 0, 0, port, '127.0.0.1', function(err, len) { }); var interval = setInterval(function() {

client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall(function() {}));
const timer = setTimeout(function() { }, 10);
throw new Error('Timeout'); }));
}, common.platformTimeout(200));
});
34 changes: 34 additions & 0 deletions test/parallel/test-dgram-send-empty-packet.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';
const common = require('../common');
const assert = require('assert');

if (common.isOSX) {
common.skip('because of 17894467 Apple bug');
return;
}

const dgram = require('dgram');

const client = dgram.createSocket('udp4');

client.bind(0, common.mustCall(function() {

client.on('message', common.mustCall(callback));

const port = this.address().port;
const buf = Buffer.alloc(1);

const interval = setInterval(function() {
client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall(callback));
}, 10);

function callback(firstArg) {
// If client.send() callback, firstArg should be null.
// If client.on('message') listener, firstArg should be a 0-length buffer.
if (firstArg instanceof Buffer) {
assert.strictEqual(firstArg.length, 0);
clearInterval(interval);
client.close();
}
}
}));

0 comments on commit 9b0f53d

Please sign in to comment.