Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Revert breaking changes for detectOpenHandles #14789

Merged
merged 5 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369))
- `[jest-config]` [**BREAKING**] Update `testMatch` and `testRegex` default option for supporting `mjs`, `cjs`, `mts`, and `cts` ([#14584](https://github.com/jestjs/jest/pull/14584))
- `[jest-config]` Loads config file from provided path in `package.json` ([#14044](https://github.com/facebook/jest/pull/14044))
- `[@jest/core]` [**BREAKING**] Group together open handles with the same stack trace ([#13417](https://github.com/jestjs/jest/pull/13417), & [#14543](https://github.com/jestjs/jest/pull/14543))
- `[@jest/core]` Group together open handles with the same stack trace ([#13417](https://github.com/jestjs/jest/pull/13417), & [#14789](https://github.com/jestjs/jest/pull/14789))
- `[@jest/core]` Add `perfStats` to surface test setup overhead ([#14622](https://github.com/jestjs/jest/pull/14622))
- `[@jest/core]` [**BREAKING**] Changed `--filter` to accept an object with shape `{ filtered: Array<string> }` to match [documentation](https://jestjs.io/docs/cli#--filterfile) ([#13319](https://github.com/jestjs/jest/pull/13319))
- `[@jest/core, @jest/test-sequencer]` [**BREAKING**] Exposes `globalConfig` & `contexts` to `TestSequencer` ([#14535](https://github.com/jestjs/jest/pull/14535), & [#14543](https://github.com/jestjs/jest/pull/14543))
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`prints message about flag on slow tests with a custom timeout 1`] = `
exports[`prints out info about open handlers 1`] = `
"Jest has detected the following 1 open handle potentially keeping Jest from exiting:

DNSCHANNEL,TCPSERVERWRAP
● TCPSERVERWRAP

12 | const app = new Server();
13 |
Expand Down
12 changes: 3 additions & 9 deletions packages/jest-core/src/__tests__/collectHandles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ describe('collectHandles', () => {
it('should not collect the PerformanceObserver open handle', async () => {
const handleCollector = collectHandles();

let obs = new PerformanceObserver((list, observer) => {});
const obs = new PerformanceObserver((list, observer) => {});
obs.observe({entryTypes: ['mark']});
obs.disconnect();
obs = null;

const openHandles = await handleCollector();

Expand All @@ -47,12 +45,9 @@ describe('collectHandles', () => {
it('should not collect the DNSCHANNEL open handle', async () => {
const handleCollector = collectHandles();

let resolver = new dns.Resolver();
const resolver = new dns.Resolver();
resolver.getServers();

// We must drop references to it
resolver = null;

const openHandles = await handleCollector();

expect(openHandles).not.toContainEqual(
Expand Down Expand Up @@ -141,11 +136,10 @@ describe('collectHandles', () => {
);
});

it('should not be false positives for some special objects such as `TLSWRAP`', async () => {
it('should not collect the `TLSWRAP` open handle', async () => {
const handleCollector = collectHandles();

const socket = new TLSSocket();
socket.destroy();

const openHandles = await handleCollector();

Expand Down
17 changes: 14 additions & 3 deletions packages/jest-core/src/collectHandles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,20 @@ export default function collectHandles(): HandleCollectionResult {
// Skip resources that should not generally prevent the process from
// exiting, not last a meaningfully long time, or otherwise shouldn't be
// tracked.
if (type === 'PROMISE') {
if (
[
'PROMISE',
'TIMERWRAP',
'ELDHISTOGRAM',
'PerformanceObserver',
'RANDOMBYTESREQUEST',
'DNSCHANNEL',
'ZLIB',
'SIGNREQUEST',
'TLSWRAP',
'TCPWRAP',
].includes(type)
) {
return;
}
const error = new ErrorWithStack(type, initHook, 100);
Expand Down Expand Up @@ -136,8 +149,6 @@ export default function collectHandles(): HandleCollectionResult {
await asyncSleep(30);

if (activeHandles.size > 0) {
// For some special objects such as `TLSWRAP`.
// Ref: https://github.com/jestjs/jest/issues/11665
runGC();

await asyncSleep(0);
Expand Down
Loading