-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dgram: use common.mustCall and common.platformTimeout in send tests
Fixes situations were some events were not asserted to be emitted. Removed some flakyness from tests.
- Loading branch information
Showing
5 changed files
with
25 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
'use strict'; | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var dgram = require('dgram'); | ||
var client, timer, buf, len, offset; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const dgram = require('dgram'); | ||
const client = dgram.createSocket('udp4'); | ||
|
||
client = dgram.createSocket('udp4'); | ||
|
||
buf = Buffer.allocUnsafe(256); | ||
offset = 20; | ||
|
||
len = buf.length - offset; | ||
const timer = setTimeout(function() { | ||
throw new Error('Timeout'); | ||
}, common.platformTimeout(200)); | ||
|
||
const buf = Buffer.allocUnsafe(256); | ||
const offset = 20; | ||
const len = buf.length - offset; | ||
|
||
client.send(buf, offset, len, common.PORT, '127.0.0.1', function(err, bytes) { | ||
const messageSent = common.mustCall(function messageSent(err, bytes) { | ||
assert.notEqual(bytes, buf.length); | ||
assert.equal(bytes, buf.length - offset); | ||
clearTimeout(timer); | ||
client.close(); | ||
}); | ||
|
||
timer = setTimeout(function() { | ||
throw new Error('Timeout'); | ||
}, 200); | ||
client.send(buf, offset, len, common.PORT, '127.0.0.1', messageSent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters