Skip to content

Commit ca84718

Browse files
committed
test: simplify http agent test comments
Signed-off-by: Ic3b3rg <s.ceccarini94@gmail.com>
1 parent d31a07d commit ca84718

3 files changed

Lines changed: 10 additions & 19 deletions

File tree

‎test/parallel/test-http-agent-idle-async-context-gc.js‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ const { AsyncLocalStorage } = require('node:async_hooks');
88
const { once } = require('node:events');
99
const http = require('node:http');
1010

11-
// This test ensures that an idle keep-alive socket does not retain the
12-
// context of the requests that created and reused it, through either its
13-
// handle or its timeout.
11+
// Idle keep-alive sockets must release request contexts held by their
12+
// handles and timeout timers.
1413
// Refs: https://github.com/nodejs/node/issues/67181
1514

1615
const storage = new AsyncLocalStorage();
@@ -28,8 +27,8 @@ function requestInContext() {
2827
const store = {};
2928
const reference = new WeakRef(store);
3029
return storage.run(store, common.mustCall(() => new Promise((resolve, reject) => {
31-
// Use an IP address, so the first DNS lookup does not create the default
32-
// resolver, which keeps the context it was created in, inside the store.
30+
// Avoid initializing the default DNS resolver inside ALS: it can retain
31+
// the request context independently of the Agent.
3332
http.get({
3433
agent,
3534
host: '127.0.0.1',

‎test/parallel/test-http-agent-idle-async-context.js‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ const { once } = require('node:events');
77
const http = require('node:http');
88
const { setImmediate } = require('node:timers/promises');
99

10-
// This test ensures that a keep-alive socket runs its callbacks in the context
11-
// of the request currently using it, and in no request context while it is
12-
// idle in the agent pool. Other work started by a request must keep its
13-
// context after the socket is released.
10+
// Idle socket callbacks must not inherit a completed request's context.
11+
// Active requests and independent asynchronous work must keep theirs.
1412
// Refs: https://github.com/nodejs/node/issues/67181
1513

1614
const storage = new AsyncLocalStorage();
@@ -66,8 +64,6 @@ async function main() {
6664
await setImmediate();
6765
assertPooled(created);
6866

69-
// A request that reuses the socket must observe its own context in the
70-
// socket timeout.
7167
const secondStore = { requestId: 'second' };
7268
await storage.run(secondStore, common.mustCall(() => new Promise((resolve) => {
7369
const req = request('/stall');
@@ -82,12 +78,9 @@ async function main() {
8278
req.on('close', common.mustCall(resolve));
8379
})));
8480

85-
// Releasing the socket must not alter the context of other work.
8681
releaseBackgroundWork();
8782
await backgroundWork;
8883

89-
// An idle socket times out and is closed by the agent outside of the
90-
// context of the request that created it.
9184
const thirdStore = { requestId: 'third' };
9285
const idle = await storage.run(thirdStore,
9386
common.mustCall(() => completedRequest(thirdStore)));

‎test/parallel/test-https-agent-idle-async-context-gc.js‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ const { AsyncLocalStorage } = require('node:async_hooks');
1212
const { once } = require('node:events');
1313
const https = require('node:https');
1414

15-
// This test ensures that an idle keep-alive TLS socket does not retain the
16-
// context of the requests that created and reused it, through either its
17-
// handles, including the TCP handle beneath TLS, or its timeout.
15+
// Idle TLS sockets must release request contexts held by their timeout
16+
// timers and handles, including the TCP handle beneath TLS.
1817
// Refs: https://github.com/nodejs/node/issues/67181
1918

2019
const storage = new AsyncLocalStorage();
@@ -37,8 +36,8 @@ function requestInContext() {
3736
const store = {};
3837
const reference = new WeakRef(store);
3938
return storage.run(store, common.mustCall(() => new Promise((resolve, reject) => {
40-
// Use an IP address, so the first DNS lookup does not create the default
41-
// resolver, which keeps the context it was created in, inside the store.
39+
// Avoid initializing the default DNS resolver inside ALS: it can retain
40+
// the request context independently of the Agent.
4241
https.get({
4342
agent,
4443
host: '127.0.0.1',

0 commit comments

Comments
 (0)