Skip to content

Commit

Permalink
Ignore DNSCHANNEL when using --detectOpenHandles (#11470)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr0grog authored May 28, 2021
1 parent 8b0a342 commit 4cae680
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Fixes

- `[jest-circus, @jest/test-sequencer]` Remove dependency on `jest-runner` ([#11466](https://github.com/facebook/jest/pull/11466))
- `[jest-core]` Do not warn about `DNSCHANNEL` handles when using the `--detectOpenHandles` option ([#11470](https://github.com/facebook/jest/pull/11470))
- `[jest-runner]` Remove dependency on `jest-config` ([#11466](https://github.com/facebook/jest/pull/11466))
- `[jest-worker]` Loosen engine requirement to `>= 10.13.0` ([#11451](https://github.com/facebook/jest/pull/11451))

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 @@ -13,7 +13,7 @@ This usually means that there are asynchronous operations that weren't stopped i
exports[`prints out info about open handlers 1`] = `
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
DNSCHANNEL
TCPSERVERWRAP
12 | const app = new Server();
13 |
Expand Down
14 changes: 14 additions & 0 deletions packages/jest-core/src/__tests__/collectHandles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
*/

import {promises as dns} from 'dns';
import http from 'http';
import {PerformanceObserver} from 'perf_hooks';
import collectHandles from '../collectHandles';
Expand Down Expand Up @@ -38,6 +39,19 @@ describe('collectHandles', () => {
obs.disconnect();
});

it('should not collect the DNSCHANNEL open handle', async () => {
const handleCollector = collectHandles();

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

const openHandles = await handleCollector();

expect(openHandles).not.toContainEqual(
expect.objectContaining({message: 'DNSCHANNEL'}),
);
});

it('should collect handles opened in test functions with `done` callbacks', done => {
const handleCollector = collectHandles();
const server = http.createServer((_, response) => response.end('ok'));
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-core/src/collectHandles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ export default function collectHandles(): HandleCollectionResult {
triggerAsyncId,
resource: {} | NodeJS.Timeout,
) {
// 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' ||
type === 'TIMERWRAP' ||
type === 'ELDHISTOGRAM' ||
type === 'PerformanceObserver' ||
type === 'RANDOMBYTESREQUEST'
type === 'RANDOMBYTESREQUEST' ||
type === 'DNSCHANNEL'
) {
return;
}
Expand Down

0 comments on commit 4cae680

Please sign in to comment.