Skip to content

Commit cc646df

Browse files
committed
Optional logging of active Node handles in gulp
This commit adds optional logging of open sockets, file handles, etc. to the gulp script. Logging happens after various NodeJS test task that can theoretically leave unclosed resources after execution. Logging is turned off by default. It happened to be very useful when NodeJS process does not exit after tests because of open `TLSSocket` objects.
1 parent 5ccf9b0 commit cc646df

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

gulpfile.babel.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ var file = require('gulp-file');
4848
var semver = require('semver');
4949
var sharedNeo4j = require('./test/internal/shared-neo4j').default;
5050

51+
/**
52+
* Useful to investigate resource leaks in tests. Enable to see active sockets and file handles after the 'test' task.
53+
*/
54+
var enableActiveNodeHandlesLogging = false;
55+
5156
gulp.task('default', ["test"]);
5257

5358
gulp.task('browser', function(cb){
@@ -165,15 +170,15 @@ gulp.task('test-nodejs', ['install-driver-into-sandbox'], function () {
165170
.pipe(jasmine({
166171
includeStackTrace: true,
167172
verbose: true
168-
}));
173+
})).on('end', logActiveNodeHandles);
169174
});
170175

171176
gulp.task('test-boltkit', ['nodejs'], function () {
172177
return gulp.src('test/**/*.boltkit.it.js')
173178
.pipe(jasmine({
174179
includeStackTrace: true,
175180
verbose: true
176-
}));
181+
})).on('end', logActiveNodeHandles);
177182
});
178183

179184
gulp.task('test-browser', function (cb) {
@@ -210,7 +215,7 @@ gulp.task('run-tck', ['download-tck', 'nodejs'], function() {
210215
'steps': 'test/v1/tck/steps/*.js',
211216
'format': 'progress',
212217
'tags' : ['~@fixed_session_pool', '~@db', '~@equality', '~@streaming_and_cursor_navigation']
213-
}));
218+
})).on('end', logActiveNodeHandles);
214219
});
215220

216221
/** Set the project version, controls package.json and version.js */
@@ -248,5 +253,11 @@ gulp.task('run-stress-tests', function () {
248253
.pipe(jasmine({
249254
includeStackTrace: true,
250255
verbose: true
251-
}));
256+
})).on('end', logActiveNodeHandles);
252257
});
258+
259+
function logActiveNodeHandles() {
260+
if (enableActiveNodeHandlesLogging) {
261+
console.log('-- Active NodeJS handles START\n', process._getActiveHandles(), '\n-- Active NodeJS handles END');
262+
}
263+
}

0 commit comments

Comments
 (0)