Skip to content

Commit 9cfddee

Browse files
requested changes
1 parent 2c68f22 commit 9cfddee

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{"ev":{"name":"serverHeartbeatSucceeded","connectionId":"localhost:31000","duration":4,"reply":{"topologyVersion":{"processId":"67917651e47cc2d141909817","counter":6},"hosts":["localhost:31000","localhost:31001","localhost:31002"],"arbiters":["localhost:31003"],"setName":"rs","setVersion":1,"isWritablePrimary":true,"secondary":false,"primary":"localhost:31000","me":"localhost:31000","electionId":"7fffffff0000000000000001","lastWrite":{"opTime":{"ts":{"$timestamp":"7462881799971012609"},"t":1},"lastWriteDate":"2025-01-22T23:12:53.000Z","majorityOpTime":{"ts":{"$timestamp":"7462881799971012609"},"t":1},"majorityWriteDate":"2025-01-22T23:12:53.000Z"},"maxBsonObjectSize":16777216,"maxMessageSizeBytes":48000000,"maxWriteBatchSize":100000,"localTime":"2025-01-22T23:13:01.572Z","logicalSessionTimeoutMinutes":30,"connectionId":374,"minWireVersion":0,"maxWireVersion":21,"readOnly":false,"ok":1,"$clusterTime":{"clusterTime":{"$timestamp":"7462881799971012609"},"signature":{"hash":"0ZNDkBzDMPYZGu7Xf3UGFzhng/A=","keyId":{"low":5,"high":1737586273,"unsigned":false}}},"operationTime":{"$timestamp":"7462881799971012609"}},"awaited":true}}
2+
{"ev":{"name":"serverHeartbeatSucceeded","connectionId":"localhost:31003","duration":2,"reply":{"topologyVersion":{"processId":"679176542928a27b6927e95d","counter":2},"hosts":["localhost:31000","localhost:31001","localhost:31002"],"arbiters":["localhost:31003"],"setName":"rs","setVersion":1,"isWritablePrimary":false,"secondary":false,"primary":"localhost:31000","arbiterOnly":true,"me":"localhost:31003","lastWrite":{"opTime":{"ts":{"$timestamp":"7462881799971012609"},"t":1},"lastWriteDate":"2025-01-22T23:12:53.000Z","majorityOpTime":{"ts":{"$timestamp":"7462881799971012609"},"t":1},"majorityWriteDate":"2025-01-22T23:12:53.000Z"},"maxBsonObjectSize":16777216,"maxMessageSizeBytes":48000000,"maxWriteBatchSize":100000,"localTime":"2025-01-22T23:13:01.577Z","logicalSessionTimeoutMinutes":30,"connectionId":169,"minWireVersion":0,"maxWireVersion":21,"readOnly":false,"ok":1},"awaited":true}}
3+
{"ev":{"name":"serverHeartbeatSucceeded","connectionId":"localhost:31001","duration":2,"reply":{"topologyVersion":{"processId":"67917652195aa0dc84acece6","counter":4},"hosts":["localhost:31000","localhost:31001","localhost:31002"],"arbiters":["localhost:31003"],"setName":"rs","setVersion":1,"isWritablePrimary":false,"secondary":true,"primary":"localhost:31000","me":"localhost:31001","lastWrite":{"opTime":{"ts":{"$timestamp":"7462881799971012609"},"t":1},"lastWriteDate":"2025-01-22T23:12:53.000Z","majorityOpTime":{"ts":{"$timestamp":"7462881799971012609"},"t":1},"majorityWriteDate":"2025-01-22T23:12:53.000Z"},"maxBsonObjectSize":16777216,"maxMessageSizeBytes":48000000,"maxWriteBatchSize":100000,"localTime":"2025-01-22T23:13:01.578Z","logicalSessionTimeoutMinutes":30,"connectionId":200,"minWireVersion":0,"maxWireVersion":21,"readOnly":false,"ok":1,"$clusterTime":{"clusterTime":{"$timestamp":"7462881799971012609"},"signature":{"hash":"0ZNDkBzDMPYZGu7Xf3UGFzhng/A=","keyId":{"low":5,"high":1737586273,"unsigned":false}}},"operationTime":{"$timestamp":"7462881799971012609"}},"awaited":true}}
4+
{"ev":{"name":"serverHeartbeatSucceeded","connectionId":"localhost:31002","duration":2,"reply":{"topologyVersion":{"processId":"6791765368696db3e1252bb1","counter":4},"hosts":["localhost:31000","localhost:31001","localhost:31002"],"arbiters":["localhost:31003"],"setName":"rs","setVersion":1,"isWritablePrimary":false,"secondary":true,"primary":"localhost:31000","me":"localhost:31002","lastWrite":{"opTime":{"ts":{"$timestamp":"7462881799971012609"},"t":1},"lastWriteDate":"2025-01-22T23:12:53.000Z","majorityOpTime":{"ts":{"$timestamp":"7462881799971012609"},"t":1},"majorityWriteDate":"2025-01-22T23:12:53.000Z"},"maxBsonObjectSize":16777216,"maxMessageSizeBytes":48000000,"maxWriteBatchSize":100000,"localTime":"2025-01-22T23:13:01.579Z","logicalSessionTimeoutMinutes":30,"connectionId":201,"minWireVersion":0,"maxWireVersion":21,"readOnly":false,"ok":1,"$clusterTime":{"clusterTime":{"$timestamp":"7462881799971012609"},"signature":{"hash":"0ZNDkBzDMPYZGu7Xf3UGFzhng/A=","keyId":{"low":5,"high":1737586273,"unsigned":false}}},"operationTime":{"$timestamp":"7462881799971012609"}},"awaited":true}}
5+
{"socketsAfterClose":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000129e1e690","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000013b10eb50","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000013b009eb0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000013b009c00","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000139f41c80","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":true,"is_referenced":true,"address":"0x000000013b00ff90","localEndpoint":{"host":"localhost","port":65364},"remoteEndpoint":{"host":"localhost","port":31000},"sendBufferSize":146808,"recvBufferSize":407800,"fd":26,"writeQueueSize":0,"readable":true,"writable":true},{"type":"tcp","is_active":true,"is_referenced":true,"address":"0x000000010ab0a9e0","localEndpoint":{"host":"localhost","port":65365},"remoteEndpoint":{"host":"localhost","port":31001},"sendBufferSize":146808,"recvBufferSize":407800,"fd":28,"writeQueueSize":0,"readable":true,"writable":true},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000010ab0ab90","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000010ab0af40","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}]}
6+
{"error":{"message":"expected [ 'localhost:31000', …(3) ] to have a length of +0 but got 4","stack":"AssertionError: expected [ 'localhost:31000', …(3) ] to have a length of +0 but got 4\n at func (/Users/aditi.khare/Desktop/node-mongodb-native/socket-connection-rtt-monitoring.cjs:35:81)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async main (/Users/aditi.khare/Desktop/node-mongodb-native/socket-connection-rtt-monitoring.cjs:145:3)","resources":{"libuvResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000129e1e690","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000013b10eb50","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000013b009eb0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000013b009c00","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000139f41c80","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":true,"is_referenced":true,"address":"0x000000013b00ff90","localEndpoint":{"host":"localhost","port":65364},"remoteEndpoint":{"host":"localhost","port":31000},"sendBufferSize":146808,"recvBufferSize":407800,"fd":26,"writeQueueSize":0,"readable":true,"writable":true},{"type":"tcp","is_active":true,"is_referenced":true,"address":"0x000000010ab0a9e0","localEndpoint":{"host":"localhost","port":65365},"remoteEndpoint":{"host":"localhost","port":31001},"sendBufferSize":146808,"recvBufferSize":407800,"fd":28,"writeQueueSize":0,"readable":true,"writable":true},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000010ab0ab90","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false},{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000010ab0af40","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],"activeResources":["ConnectWrap","ConnectWrap","TCPSocketWrap","TCPSocketWrap","TCPSocketWrap","TCPSocketWrap","TCPSocketWrap","TCPSocketWrap","TCPSocketWrap","TCPSocketWrap","TCPSocketWrap","Timeout","Timeout"]}}}

test/integration/node-specific/client_close.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { type TestConfiguration } from '../../tools/runner/config';
33
import { runScriptAndGetProcessInfo } from './resource_tracking_script_builder';
44

5-
describe.skip('MongoClient.close() Integration', () => {
5+
describe.only('MongoClient.close() Integration', () => {
66
// note: these tests are set-up in accordance of the resource ownership tree
77

88
let config: TestConfiguration;
@@ -246,8 +246,8 @@ describe.skip('MongoClient.close() Integration', () => {
246246
describe('Connection', () => {
247247
describe('Node.js resource: Socket', () => {
248248
describe('when rtt monitoring is turned on', () => {
249-
it('no sockets remain after client.close()', metadata, async () => {
250-
const run = async ({ MongoClient, uri, expect, getSockets, once }) => {
249+
it.only('no sockets remain after client.close()', metadata, async () => {
250+
const run = async ({ MongoClient, uri, expect, getSockets, once, log }) => {
251251
const heartbeatFrequencyMS = 500;
252252
const client = new MongoClient(uri, {
253253
serverMonitoringMode: 'stream',
@@ -263,9 +263,9 @@ describe.skip('MongoClient.close() Integration', () => {
263263
const servers = client.topology.s.servers;
264264

265265
while (heartbeatOccurredSet.size < servers.size) {
266-
await once(client, 'serverHeartbeatSucceeded', ev => {
267-
heartbeatOccurredSet.add(ev.connectionId);
268-
});
266+
const ev = await once(client, 'serverHeartbeatSucceeded');
267+
log({ ev: ev[0] })
268+
heartbeatOccurredSet.add(ev[0].connectionId);
269269
}
270270

271271
const activeSocketsAfterHeartbeat = () =>
@@ -281,6 +281,7 @@ describe.skip('MongoClient.close() Integration', () => {
281281
// close the client
282282
await client.close();
283283

284+
log({ socketsAfterClose: getSockets() });
284285
// upon close, assert rttPinger sockets are cleaned up
285286
const activeSocketsAfterClose = activeSocketsAfterHeartbeat();
286287
expect(activeSocketsAfterClose).to.have.lengthOf(0);

test/integration/node-specific/resource_tracking_script_builder.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { fork, spawn } from 'node:child_process';
22
import { on, once } from 'node:events';
33
import { readFile, unlink, writeFile } from 'node:fs/promises';
44
import * as path from 'node:path';
5+
import { openSync, statSync } from 'node:fs';
56

67
import { AssertionError, expect } from 'chai';
78
import type * as timers from 'timers';
@@ -176,7 +177,8 @@ export async function runScriptAndGetProcessInfo(
176177
await writeFile(scriptName, scriptContent, { encoding: 'utf8' });
177178
const logFile = name + '.logs.txt';
178179

179-
const script = spawn(process.execPath, [scriptName], { stdio: ['ignore', 'ignore', 'inherit'] });
180+
const stdErrFile = 'err.out';
181+
const script = spawn(process.execPath, [scriptName], { stdio: ['ignore', 'ignore', openSync(stdErrFile, 'w')] });
180182

181183
const willClose = once(script, 'close');
182184

@@ -190,9 +192,12 @@ export async function runScriptAndGetProcessInfo(
190192
.map(line => JSON.parse(line))
191193
.reduce((acc, curr) => ({ ...acc, ...curr }), {});
192194

195+
const stdErrSize = statSync(stdErrFile).size;
196+
193197
// delete temporary files
194198
await unlink(scriptName);
195-
await unlink(logFile);
199+
// await unlink(logFile);
200+
await unlink(stdErrFile);
196201

197202
// assertions about exit status
198203
if (exitCode) {
@@ -203,6 +208,9 @@ export async function runScriptAndGetProcessInfo(
203208
throw assertionError;
204209
}
205210

211+
// assertion about error output
212+
expect(stdErrSize).to.equal(0);
213+
206214
// assertions about resource status
207215
expect(messages.beforeExitHappened).to.be.true;
208216
expect(messages.newResources.libuvResources).to.be.empty;

test/tools/fixtures/process_resource_script.in.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ function getNewLibuvResourceArray() {
7272
* - `process.getActiveResourcesInfo()` does not contain enough server information we need for our assertions
7373
*
7474
*/
75+
7576
function getNewResources() {
7677
return {
7778
libuvResources: getNewLibuvResourceArray(),
78-
activeResources: process.getActiveResourcesInfo().filter(r => r !== 'TTYWrap')
79+
activeResources: process.getActiveResourcesInfo()
7980
};
8081
}
8182

0 commit comments

Comments
 (0)