-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add coverage for dgram _createSocketHandle()
This commit adds code coverage to _createSocketHandle(), which the cluster module uses to create dgram sockets. PR-URL: #11291 Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
b140dec
commit 93d3a3a
Showing
1 changed file
with
39 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const dgram = require('dgram'); | ||
const UDP = process.binding('udp_wrap').UDP; | ||
const _createSocketHandle = dgram._createSocketHandle; | ||
|
||
// Throws if an "existing fd" is passed in. | ||
assert.throws(() => { | ||
_createSocketHandle(common.localhostIPv4, 0, 'udp4', 42); | ||
}, /^AssertionError: false == true$/); | ||
|
||
{ | ||
// Create a handle that is not bound. | ||
const handle = _createSocketHandle(null, null, 'udp4'); | ||
|
||
assert(handle instanceof UDP); | ||
assert.strictEqual(typeof handle.fd, 'number'); | ||
assert(handle.fd < 0); | ||
} | ||
|
||
{ | ||
// Create a bound handle. | ||
const handle = _createSocketHandle(common.localhostIPv4, 0, 'udp4'); | ||
|
||
assert(handle instanceof UDP); | ||
assert.strictEqual(typeof handle.fd, 'number'); | ||
|
||
if (!common.isWindows) | ||
assert(handle.fd > 0); | ||
} | ||
|
||
{ | ||
// Return an error if binding fails. | ||
const err = _createSocketHandle('localhost', 0, 'udp4'); | ||
|
||
assert.strictEqual(typeof err, 'number'); | ||
assert(err < 0); | ||
} |