Skip to content

Commit 62d80e4

Browse files
committed
test: move wtfnode invocation to signal handlers on main test runner
We had previously been running a `wtfnode` dump at the end of all test runs as part of the client leak checker plugin. This is faulty because it might catch false positive handles which are closing at the time of test runner cleanup. If something is actually leaked, it will now be caught at the time the test suite is cancelled (either manually or in CI), and give better diagnostics about the leaked handles.
1 parent be51347 commit 62d80e4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

test/tools/runner/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const parseConnectionString = require('../../../lib/core/uri_parser');
88
const eachAsync = require('../../../lib/core/utils').eachAsync;
99
const mock = require('mongodb-mock-server');
1010
const chalk = require('chalk');
11+
const wtfnode = require('wtfnode');
1112

1213
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017';
1314
const filters = [];
@@ -107,3 +108,20 @@ chai.use(require('../../functional/spec-runner/matcher').default);
107108
chai.config.includeStack = true;
108109
chai.config.showDiff = true;
109110
chai.config.truncateThreshold = 0;
111+
112+
// install signal handlers for printing open/active handles
113+
function dumpAndExit() {
114+
// let other potential handlers run before exiting
115+
process.nextTick(function() {
116+
try {
117+
wtfnode.dump();
118+
} catch (e) {
119+
console.log(e);
120+
}
121+
122+
process.exit();
123+
});
124+
}
125+
126+
process.on('SIGINT', dumpAndExit);
127+
process.on('SIGTERM', dumpAndExit);

test/tools/runner/plugins/client_leak_checker.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const TestConfiguration = require('../config');
4-
const wtfnode = require('wtfnode');
54
const chalk = require('chalk');
65

76
let activeClients = [];
@@ -31,8 +30,6 @@ function unifiedTopologyIsConnected(client) {
3130
}
3231

3332
after(function() {
34-
wtfnode.dump();
35-
3633
const isUnifiedTopology = this.configuration.usingUnifiedTopology;
3734
const traces = [];
3835
const openClientCount = activeClients.reduce((count, client) => {
@@ -55,3 +52,4 @@ after(function() {
5552

5653
activeClients = [];
5754
});
55+

0 commit comments

Comments
 (0)