0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-dgram-close-signal.js
Wassim Chegham eaadc4bd30 test: refactor code to use AbortSignal.abort()
PR-URL: https://github.com/nodejs/node/pull/37798
Refs: https://github.com/whatwg/dom/pull/960
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
2021-03-20 19:21:13 +01:00

32 lines
709 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
{
// Test bad signal.
assert.throws(
() => dgram.createSocket({ type: 'udp4', signal: {} }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
});
}
{
// Test close.
const controller = new AbortController();
const { signal } = controller;
const server = dgram.createSocket({ type: 'udp4', signal });
server.on('close', common.mustCall());
controller.abort();
}
{
// Test close with pre-aborted signal.
const signal = AbortSignal.abort();
const server = dgram.createSocket({ type: 'udp4', signal });
server.on('close', common.mustCall());
}