-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactor test-abortcontroller to use node:test
Starting the long process of refactoring our own tests to use the node:test module and mocks. PR-URL: #54574 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
- Loading branch information
Showing
2 changed files
with
142 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Flags: --no-warnings --expose-gc --expose-internals | ||
'use strict'; | ||
require('../common'); | ||
|
||
const { | ||
strictEqual, | ||
} = require('assert'); | ||
|
||
const { | ||
test, | ||
} = require('node:test'); | ||
|
||
const { | ||
kWeakHandler, | ||
} = require('internal/event_target'); | ||
|
||
const { setTimeout: sleep } = require('timers/promises'); | ||
|
||
// The tests in this file depend on Node.js internal APIs. These are not necessarily | ||
// portable to other runtimes | ||
|
||
test('A weak event listener should not prevent gc', async () => { | ||
// If the event listener is weak, however, it should not prevent gc | ||
let ref; | ||
function handler() {} | ||
{ | ||
ref = new globalThis.WeakRef(AbortSignal.timeout(1_200_000)); | ||
ref.deref().addEventListener('abort', handler, { [kWeakHandler]: {} }); | ||
} | ||
|
||
await sleep(10); | ||
globalThis.gc(); | ||
strictEqual(ref.deref(), undefined); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters