mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
fe2b5f0dd2
This test wasn't actually working, as sockets were being closed, allowing the test to exit before any assertions were actually run. This commit refactors the test to maintain the same intended semantics. PR-URL: https://github.com/nodejs/node/pull/11252 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
26 lines
552 B
JavaScript
26 lines
552 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const dgram = require('dgram');
|
|
|
|
{
|
|
// Should throw EBADF if the socket is never bound.
|
|
const socket = dgram.createSocket('udp4');
|
|
|
|
assert.throws(() => {
|
|
socket.setBroadcast(true);
|
|
}, /^Error: setBroadcast EBADF$/);
|
|
}
|
|
|
|
{
|
|
// Can call setBroadcast() after binding the socket.
|
|
const socket = dgram.createSocket('udp4');
|
|
|
|
socket.bind(0, common.mustCall(() => {
|
|
socket.setBroadcast(true);
|
|
socket.setBroadcast(false);
|
|
socket.close();
|
|
}));
|
|
}
|