diff --git a/test/parallel/test-dgram-multicast-loopback.js b/test/parallel/test-dgram-multicast-loopback.js index 01def7e28160cd..c1eedcd1c98900 100644 --- a/test/parallel/test-dgram-multicast-loopback.js +++ b/test/parallel/test-dgram-multicast-loopback.js @@ -2,11 +2,22 @@ const common = require('../common'); const assert = require('assert'); const dgram = require('dgram'); -const socket = dgram.createSocket('udp4'); - -socket.bind(0); -socket.on('listening', common.mustCall(() => { - const result = socket.setMulticastLoopback(16); - assert.strictEqual(result, 16); - socket.close(); -})); + +{ + const socket = dgram.createSocket('udp4'); + + assert.throws(() => { + socket.setMulticastLoopback(16); + }, /^Error: setMulticastLoopback EBADF$/); +} + +{ + const socket = dgram.createSocket('udp4'); + + socket.bind(0); + socket.on('listening', common.mustCall(() => { + assert.strictEqual(socket.setMulticastLoopback(16), 16); + assert.strictEqual(socket.setMulticastLoopback(0), 0); + socket.close(); + })); +}