GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: refactor test-gc-tls-external-memory · nodejs/node@dd772c1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-gc-tls-external-memory.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-gc-tls-external-memory.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-gc-tls-external-memory.js
+30-16Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,42 @@ const common = require('../common');
88
if (!common.hasCrypto)
99
common.skip('missing crypto');
1010

11+
const makeDuplexPair = require('../common/duplexpair');
12+
const onGC = require('../common/ongc');
1113
const assert = require('assert');
12-
const net = require('net');
1314
const tls = require('tls');
1415

1516
// Payload doesn't matter. We just need to have the tls
1617
// connection try and connect somewhere.
17-
const yolo = Buffer.alloc(10000).fill('yolo');
18-
const server = net.createServer(function(socket) {
19-
socket.write(yolo);
20-
});
18+
const dummyPayload = Buffer.alloc(10000, 'yolo');
2119

22-
server.listen(0, common.mustCall(function() {
23-
const { port } = server.address();
24-
let runs = 0;
25-
connect();
20+
let runs = 0;
2621

27-
function connect() {
22+
// Count garbage-collected TLS sockets.
23+
let gced = 0;
24+
function ongc() { gced++; }
25+
26+
connect();
27+
28+
function connect() {
29+
if (runs % 64 === 0)
2830
global.gc();
29-
assert(process.memoryUsage().external >= 0);
30-
if (runs++ < 512)
31-
tls.connect(port).on('error', connect);
32-
else
33-
server.close();
31+
const externalMemoryUsage = process.memoryUsage().external;
32+
assert(externalMemoryUsage >= 0, `${externalMemoryUsage} < 0`);
33+
if (runs++ === 512) {
34+
// Make sure at least half the TLS sockets have been gargbage collected
35+
// (so that this test can actually check what it's testing):
36+
assert(gced >= 256, `${gced} < 256`);
37+
return;
3438
}
35-
}));
39+
40+
const { clientSide, serverSide } = makeDuplexPair();
41+
42+
const tlsSocket = tls.connect({ socket: clientSide });
43+
tlsSocket.on('error', common.mustCall(connect));
44+
onGC(tlsSocket, { ongc });
45+
46+
// Use setImmediate so that we don't trigger the error within the same
47+
// event loop tick.
48+
setImmediate(() => serverSide.write(dummyPayload));
49+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.