Skip to content

Commit 174a9db

Browse files
addaleaxtargos
authored andcommitted
test: refactor test-net-connect-memleak, move to parallel
This enables the test to run as part of the regular test suite. PR-URL: #21794 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b338ff5 commit 174a9db

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,32 @@ const common = require('../common');
2626
constassert=require('assert');
2727
constnet=require('net');
2828

29-
console.log('Run this test with --expose-gc');
30-
assert.strictEqual(
31-
typeofglobal.gc,
32-
'function'
33-
);
34-
net.createServer(function(){}).listen(common.PORT);
35-
36-
letbefore=0;
29+
// Test that the implicit listener for an 'connect' event on net.Sockets is
30+
// added using `once()`, i.e. can be gc'ed once that event has occurred.
31+
32+
constserver=net.createServer(common.mustCall()).listen(0);
33+
34+
letcollected=false;
35+
constgcListener={ongc(){collected=true;}};
36+
3737
{
38-
// 2**26 == 64M entries
39-
global.gc();
40-
constjunk=newArray(2**26).fill(0);
41-
before=process.memoryUsage().rss;
38+
constgcObject={};
39+
common.onGC(gcObject,gcListener);
4240

43-
net.createConnection(common.PORT,'127.0.0.1',function(){
44-
assert.notStrictEqual(junk.length,0);// keep reference alive
45-
setTimeout(done,10);
46-
global.gc();
47-
});
41+
constsock=net.createConnection(
42+
server.address().port,
43+
common.mustCall(()=>{
44+
assert.strictEqual(gcObject,gcObject);// keep reference alive
45+
assert.strictEqual(collected,false);
46+
setImmediate(done,sock);
47+
}));
4848
}
4949

50-
functiondone(){
50+
functiondone(sock){
5151
global.gc();
52-
constafter=process.memoryUsage().rss;
53-
constreclaimed=(before-after)/1024;
54-
console.log('%d kB reclaimed',reclaimed);
55-
assert(reclaimed>128*1024);// It's around 256 MB on x64.
56-
process.exit();
52+
setImmediate(()=>{
53+
assert.strictEqual(collected,true);
54+
sock.end();
55+
server.close();
56+
});
5757
}

0 commit comments

Comments
(0)