Skip to content

Commit 93d3a3a

Browse files
cjihrigitaloacasas
authored andcommitted
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 <[email protected]>
1 parent b140dec commit 93d3a3a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const dgram = require('dgram');
5+
const UDP = process.binding('udp_wrap').UDP;
6+
const _createSocketHandle = dgram._createSocketHandle;
7+
8+
// Throws if an "existing fd" is passed in.
9+
assert.throws(() => {
10+
_createSocketHandle(common.localhostIPv4, 0, 'udp4', 42);
11+
}, /^AssertionError: false == true$/);
12+
13+
{
14+
// Create a handle that is not bound.
15+
const handle = _createSocketHandle(null, null, 'udp4');
16+
17+
assert(handle instanceof UDP);
18+
assert.strictEqual(typeof handle.fd, 'number');
19+
assert(handle.fd < 0);
20+
}
21+
22+
{
23+
// Create a bound handle.
24+
const handle = _createSocketHandle(common.localhostIPv4, 0, 'udp4');
25+
26+
assert(handle instanceof UDP);
27+
assert.strictEqual(typeof handle.fd, 'number');
28+
29+
if (!common.isWindows)
30+
assert(handle.fd > 0);
31+
}
32+
33+
{
34+
// Return an error if binding fails.
35+
const err = _createSocketHandle('localhost', 0, 'udp4');
36+
37+
assert.strictEqual(typeof err, 'number');
38+
assert(err < 0);
39+
}

0 commit comments

Comments
 (0)