1import * as common from '../common/index.mjs'; 2import assert from 'node:assert'; 3import net from 'node:net'; 4import { describe, it } from 'node:test'; 5 6describe('net.Server[Symbol.asyncDispose]()', () => { 7 it('should close the server', async () => { 8 const server = net.createServer(); 9 const timeoutRef = setTimeout(common.mustNotCall(), 2 ** 31 - 1); 10 11 server.listen(0, common.mustCall(async () => { 12 await server[Symbol.asyncDispose]().then(common.mustCall()); 13 assert.strictEqual(server.address(), null); 14 clearTimeout(timeoutRef); 15 })); 16 17 server.on('close', common.mustCall()); 18 }); 19 20 it('should resolve even if the server is already closed', async () => { 21 const server = net.createServer(); 22 const timeoutRef = setTimeout(common.mustNotCall(), 2 ** 31 - 1); 23 24 server.listen(0, common.mustCall(async () => { 25 await server[Symbol.asyncDispose]().then(common.mustCall()); 26 await server[Symbol.asyncDispose]().then(common.mustCall(), common.mustNotCall()); 27 clearTimeout(timeoutRef); 28 })); 29 }); 30}); 31