Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aditi-khare-mongoDB committed Jan 22, 2025
1 parent 2c68f22 commit 9cfddee
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
6 changes: 6 additions & 0 deletions socket-connection-rtt-monitoring.logs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"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}}
{"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}}
{"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}}
{"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}}
{"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}]}
{"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"]}}}
13 changes: 7 additions & 6 deletions test/integration/node-specific/client_close.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { type TestConfiguration } from '../../tools/runner/config';
import { runScriptAndGetProcessInfo } from './resource_tracking_script_builder';

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

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

while (heartbeatOccurredSet.size < servers.size) {
await once(client, 'serverHeartbeatSucceeded', ev => {
heartbeatOccurredSet.add(ev.connectionId);
});
const ev = await once(client, 'serverHeartbeatSucceeded');
log({ ev: ev[0] })
heartbeatOccurredSet.add(ev[0].connectionId);
}

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

log({ socketsAfterClose: getSockets() });
// upon close, assert rttPinger sockets are cleaned up
const activeSocketsAfterClose = activeSocketsAfterHeartbeat();
expect(activeSocketsAfterClose).to.have.lengthOf(0);
Expand Down
12 changes: 10 additions & 2 deletions test/integration/node-specific/resource_tracking_script_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fork, spawn } from 'node:child_process';
import { on, once } from 'node:events';
import { readFile, unlink, writeFile } from 'node:fs/promises';
import * as path from 'node:path';
import { openSync, statSync } from 'node:fs';

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

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

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

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

const stdErrSize = statSync(stdErrFile).size;

// delete temporary files
await unlink(scriptName);
await unlink(logFile);
// await unlink(logFile);
await unlink(stdErrFile);

// assertions about exit status
if (exitCode) {
Expand All @@ -203,6 +208,9 @@ export async function runScriptAndGetProcessInfo(
throw assertionError;
}

// assertion about error output
expect(stdErrSize).to.equal(0);

// assertions about resource status
expect(messages.beforeExitHappened).to.be.true;
expect(messages.newResources.libuvResources).to.be.empty;
Expand Down
3 changes: 2 additions & 1 deletion test/tools/fixtures/process_resource_script.in.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ function getNewLibuvResourceArray() {
* - `process.getActiveResourcesInfo()` does not contain enough server information we need for our assertions
*
*/

function getNewResources() {
return {
libuvResources: getNewLibuvResourceArray(),
activeResources: process.getActiveResourcesInfo().filter(r => r !== 'TTYWrap')
activeResources: process.getActiveResourcesInfo()
};
}

Expand Down

0 comments on commit 9cfddee

Please sign in to comment.