Skip to content

Commit a0b2175

Browse files
committed
test: use heapdump test for SecureContext memory tracking
1 parent 726b220 commit a0b2175

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

test/cctest/test_node_crypto.cc

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,3 @@ TEST(NodeCrypto, NewRootCertStore) {
2121
"any errors on the OpenSSL error stack\n";
2222
X509_STORE_free(store);
2323
}
24-
25-
/*
26-
* This test verifies that OpenSSL memory tracking constants are properly
27-
* defined.
28-
*/
29-
TEST(NodeCrypto, MemoryTrackingConstants) {
30-
// Verify that our memory tracking constants are defined and reasonable
31-
EXPECT_GT(node::crypto::kSizeOf_SSL_CTX, 0)
32-
<< "SSL_CTX size constant should be positive";
33-
EXPECT_GT(node::crypto::kSizeOf_X509, 0)
34-
<< "X509 size constant should be positive";
35-
EXPECT_GT(node::crypto::kSizeOf_EVP_MD_CTX, 0)
36-
<< "EVP_MD_CTX size constant should be positive";
37-
38-
// Verify reasonable size ranges (basic sanity check)
39-
EXPECT_LT(node::crypto::kSizeOf_SSL_CTX, 10000)
40-
<< "SSL_CTX size should be reasonable";
41-
EXPECT_LT(node::crypto::kSizeOf_X509, 10000)
42-
<< "X509 size should be reasonable";
43-
EXPECT_LT(node::crypto::kSizeOf_EVP_MD_CTX, 1000)
44-
<< "EVP_MD_CTX size should be reasonable";
45-
46-
// Specific values we expect based on our implementation
47-
EXPECT_EQ(node::crypto::kSizeOf_SSL_CTX, 240);
48-
EXPECT_EQ(node::crypto::kSizeOf_X509, 128);
49-
EXPECT_EQ(node::crypto::kSizeOf_EVP_MD_CTX, 48);
50-
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
// This tests heap snapshot integration of SecureContext.
3+
4+
const common = require('../common');
5+
6+
if (!common.hasCrypto) common.skip('missing crypto');
7+
8+
const fixtures = require('../common/fixtures');
9+
const assert = require('assert');
10+
const {
11+
createJSHeapSnapshot,
12+
validateByRetainingPathFromNodes,
13+
} = require('../common/heap');
14+
const tls = require('tls');
15+
16+
{
17+
const nodes = createJSHeapSnapshot();
18+
const matches = nodes.filter(
19+
(n) => n.name === 'Node / SecureContext' && n.type !== 'string');
20+
assert.strictEqual(matches.length, 0);
21+
}
22+
23+
// eslint-disable-next-line no-unused-vars
24+
const ctx = tls.createSecureContext({
25+
cert: fixtures.readKey('agent1-cert.pem'),
26+
key: fixtures.readKey('agent1-key.pem'),
27+
});
28+
29+
{
30+
const nodes = createJSHeapSnapshot();
31+
validateByRetainingPathFromNodes(nodes, 'Node / SecureContext', [
32+
{ edge_name: 'ctx', node_name: 'Node / ctx' },
33+
]);
34+
validateByRetainingPathFromNodes(nodes, 'Node / SecureContext', [
35+
{ edge_name: 'cert', node_name: 'Node / cert' },
36+
]);
37+
}

0 commit comments

Comments
 (0)