11cb0ef41Sopenharmony_ciimport * as common from '../common/index.mjs';
21cb0ef41Sopenharmony_ciimport assert from 'node:assert';
31cb0ef41Sopenharmony_ciimport net from 'node:net';
41cb0ef41Sopenharmony_ciimport { describe, it } from 'node:test';
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cidescribe('net.Server[Symbol.asyncDispose]()', () => {
71cb0ef41Sopenharmony_ci  it('should close the server', async () => {
81cb0ef41Sopenharmony_ci    const server = net.createServer();
91cb0ef41Sopenharmony_ci    const timeoutRef = setTimeout(common.mustNotCall(), 2 ** 31 - 1);
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci    server.listen(0, common.mustCall(async () => {
121cb0ef41Sopenharmony_ci      await server[Symbol.asyncDispose]().then(common.mustCall());
131cb0ef41Sopenharmony_ci      assert.strictEqual(server.address(), null);
141cb0ef41Sopenharmony_ci      clearTimeout(timeoutRef);
151cb0ef41Sopenharmony_ci    }));
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci    server.on('close', common.mustCall());
181cb0ef41Sopenharmony_ci  });
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  it('should resolve even if the server is already closed', async () => {
211cb0ef41Sopenharmony_ci    const server = net.createServer();
221cb0ef41Sopenharmony_ci    const timeoutRef = setTimeout(common.mustNotCall(), 2 ** 31 - 1);
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci    server.listen(0, common.mustCall(async () => {
251cb0ef41Sopenharmony_ci      await server[Symbol.asyncDispose]().then(common.mustCall());
261cb0ef41Sopenharmony_ci      await server[Symbol.asyncDispose]().then(common.mustCall(), common.mustNotCall());
271cb0ef41Sopenharmony_ci      clearTimeout(timeoutRef);
281cb0ef41Sopenharmony_ci    }));
291cb0ef41Sopenharmony_ci  });
301cb0ef41Sopenharmony_ci});
31