|  | 
| 1 | 1 | import * as common from '../common/index.mjs'; | 
| 2 | 2 | import assert from 'node:assert'; | 
| 3 | 3 | import net from 'node:net'; | 
| 4 |  | -import { test } from 'node:test'; | 
|  | 4 | +import { describe, it } from 'node:test'; | 
| 5 | 5 | 
 | 
| 6 |  | -test('net.Server[Symbol.asyncDispose]()', () => { | 
| 7 |  | -  const server = net.createServer(); | 
|  | 6 | +describe('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); | 
| 8 | 10 | 
 | 
| 9 |  | -  server.listen(0, common.mustCall(async () => { | 
| 10 |  | -    await server[Symbol.asyncDispose]().then(common.mustCall()); | 
| 11 |  | -    assert.strictEqual(server.address(), null); | 
| 12 |  | -  })); | 
|  | 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 | +    })); | 
| 13 | 16 | 
 | 
| 14 |  | -  server.on('close', common.mustCall()); | 
|  | 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 | +  }); | 
| 15 | 30 | }); | 
0 commit comments