Skip to content

Commit f560088

Browse files
TLS test case running
1 parent 4e55dee commit f560088

File tree

6 files changed

+231
-29
lines changed

6 files changed

+231
-29
lines changed

logs.txt

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
"resources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
2+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000129e17e40","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
3+
"exitCode":0,
4+
"resources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
5+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000108504160","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
6+
"exitCode":0,
7+
"resources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
8+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000015401a1d0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
9+
"exitCode":0,
10+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
11+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000013d8098d0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
12+
"exitCode":0,
13+
"resources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
14+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000011873bfe0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
15+
"exitCode":0,
16+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
17+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000158167f00","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
18+
"exitCode":0,
19+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
20+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000150e475b0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
21+
"exitCode":0,
22+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
23+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000108205870","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
24+
"exitCode":0,
25+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
26+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000015c013ee0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
27+
"exitCode":0,
28+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
29+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000137a083b0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
30+
"exitCode":0,
31+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
32+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000108915c80","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
33+
"exitCode":0,
34+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
35+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000011a2051c0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
36+
"exitCode":0,
37+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
38+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000012470fb80","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
39+
"exitCode":0,
40+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
41+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000146744fd0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
42+
"exitCode":0,
43+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
44+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x00000001546117f0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
45+
"exitCode":0,
46+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
47+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000141e3f280","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
48+
"exitCode":0,
49+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
50+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000010a608670","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
51+
"exitCode":0,
52+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
53+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000105d09a30","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
54+
"exitCode":0,
55+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
56+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000013160fbb0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
57+
"exitCode":0,
58+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
59+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000138221de0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
60+
"exitCode":0,
61+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
62+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000013be715c0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
63+
"exitCode":0,
64+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
65+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000144741480","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
66+
"exitCode":0,
67+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
68+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x00000001456769d0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
69+
"exitCode":0,
70+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
71+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000147b08430","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
72+
"exitCode":0,
73+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
74+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000011d70ad80","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
75+
"exitCode":0,
76+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
77+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000015b841df0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
78+
"exitCode":0,
79+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000128009560","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
80+
"exitCode":0,
81+
"newResources":[],
82+
"exitCode":0,
83+
"beforeExitHappened":true,
84+
"newResources":[],
85+
"exitCode":0,
86+
"beforeExitHappened":true,
87+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000013084b1f0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
88+
"exitCode":0,
89+
"exitCode":99,
90+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
91+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000105e0f410","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
92+
"exitCode":0,
93+
"exitCode":99,
94+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
95+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000013cf08270","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
96+
"exitCode":0,
97+
"exitCode":99,
98+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TTYWrap","TTYWrap","TTYWrap","TCPSocketWrap","Timeout"],
99+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x0000000154f0d460","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
100+
"exitCode":0,
101+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
102+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000012df1f0e0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
103+
"exitCode":0,
104+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
105+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x00000001207090f0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
106+
"exitCode":0,
107+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
108+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x00000001063076c0","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
109+
"exitCode":0,
110+
"exitCode":99,
111+
"ActiveResources":["FSReqPromise","GetAddrInfoReqWrap","TCPSocketWrap","Timeout"],
112+
"newResources":[{"type":"tcp","is_active":false,"is_referenced":true,"address":"0x000000012f60cb30","localEndpoint":null,"remoteEndpoint":null,"sendBufferSize":0,"recvBufferSize":0,"writeQueueSize":0,"readable":false,"writable":false}],
113+
"exitCode":0,
114+
"exitCode":99,

src/mongo_client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
555555
options.crl ??= await fs.readFile(options.tlsCRLFile);
556556
}
557557
if (typeof options.tlsCertificateKeyFile === 'string') {
558+
console.log('here');
558559
if (!options.key || !options.cert) {
559560
const contents = await fs.readFile(options.tlsCertificateKeyFile);
560561
options.key ??= contents;

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import sinon = require('sinon');
1+
const process = require('node:process');
2+
import { expect } from 'chai';
23
import { type TestConfiguration } from '../../tools/runner/config';
34
import { runScriptAndGetProcessInfo } from './resource_tracking_script_builder';
45

5-
describe('client.close() Integration', () => {
6+
describe.skip('client.close() Integration', () => {
67
let config: TestConfiguration;
78

89
beforeEach(function () {
@@ -18,23 +19,33 @@ describe('client.close() Integration', () => {
1819
'docker-read',
1920
config,
2021
async function run({ MongoClient, uri }) {
21-
const dockerPath = '.dockerenv';
22+
/* const dockerPath = '.dockerenv';
2223
sinon.stub(fs, 'access').callsFake(async () => await sleep(5000));
2324
await fs.writeFile('.dockerenv', '', { encoding: 'utf8' });
2425
const client = new MongoClient(uri);
2526
await client.close();
26-
unlink(dockerPath);
27+
unlink(dockerPath); */
2728
}
2829
);
2930
});
3031
});
3132

32-
describe('when client is connecting and reads a TLS long file', () => {
33-
it.only('the file read is interrupted by client.close()', async () => {
33+
describe('when client is connecting and reads an infinite TLS file', () => {
34+
it('the file read is interrupted by client.close()', async function () {
3435
await runScriptAndGetProcessInfo(
35-
'docker-read',
36+
'tls-file-read',
3637
config,
37-
async function run({ MongoClient, uri }) {}
38+
async function run({ MongoClient, uri }) {
39+
const devZeroFilePath = '/dev/zero';
40+
const client = new MongoClient(uri, { tlsCertificateKeyFile: devZeroFilePath });
41+
client.connect();
42+
log({ ActiveResources: process.getActiveResourcesInfo() });
43+
chai.expect(process.getActiveResourcesInfo()).to.include('FSReqPromise');
44+
await client.close();
45+
setTimeout(() =>
46+
chai.expect(process.getActiveResourcesInfo()).to.not.include('FSReqPromise'),
47+
1000);
48+
}
3849
);
3950
});
4051
});
@@ -82,18 +93,19 @@ describe('client.close() Integration', () => {
8293
describe('ClientSession', () => {
8394
describe('after a clientSession is created and used', () => {
8495
it('the server-side ServerSession and transaction are cleaned up by client.close()', async function () {
85-
const client = this.configuration.newClient();
86-
await client.connect();
87-
const session = client.startSession();
88-
session.startTransaction();
89-
await client.db('db').collection('coll').insertOne({ a: 1 }, { session });
96+
const client = this.configuration.newClient();
97+
await client.connect();
98+
const session = client.startSession();
99+
session.startTransaction();
100+
await client.db('db').collection('coll').insertOne({ a: 1 }, { session });
90101

91-
// assert server-side session exists
102+
// assert server-side session exists
103+
expect(session.serverSession).to.exist;
92104

93-
await session.endSession();
94-
await client.close();
105+
await session.endSession();
106+
await client.close();
95107

96-
// assert command was sent to server to end server side session
108+
// assert command was sent to server to end server side session
97109
});
98110
});
99111
});

test/integration/node-specific/resource_tracking_script_builder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { fork, spawn } from 'node:child_process';
22
import { on, once } from 'node:events';
3-
import { readFile, unlink, writeFile } from 'node:fs/promises';
43
import * as fs from 'node:fs';
4+
import { readFile, unlink, writeFile } from 'node:fs/promises';
5+
import * as path from 'node:path';
56

67
import { expect } from 'chai';
78
import { parseSnapshot } from 'v8-heapsnapshot';
89

910
import { type MongoClient } from '../../mongodb';
1011
import { type TestConfiguration } from '../../tools/runner/config';
11-
import path = require('node:path');
1212

1313
export type ResourceTestFunction = HeapResourceTestFunction | ProcessResourceTestFunction;
1414

@@ -185,8 +185,8 @@ export async function runScriptAndGetProcessInfo(
185185
const formattedLogRead = '{' + fs.readFileSync(logFile, 'utf-8').slice(0, -3) + '}';
186186
const messages = JSON.parse(formattedLogRead);
187187

188-
await unlink(scriptName);
189-
await unlink('logs.txt');
188+
//await unlink(scriptName);
189+
//await unlink(logFile);
190190

191191
// assertions about exit status
192192
expect(exitCode, 'process should have exited with zero').to.equal(0);
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
/* eslint-disable no-undef */
4-
54
const driverPath = DRIVER_SOURCE_PATH;
65
const func = FUNCTION_STRING;
76
const name = NAME_STRING;
@@ -13,33 +12,34 @@ const v8 = require('node:v8');
1312
const util = require('node:util');
1413
const timers = require('node:timers');
1514
const fs = require('node:fs');
16-
const sinon = require('sinon');
15+
const chai = require('chai');
16+
1717
let originalReport;
1818
const logFile = 'logs.txt';
1919

2020
const run = func;
2121

22-
// Returns an array containing new the resources th
22+
// Returns an array containing new the resources created after script start
2323
function getNewResourceArray() {
2424
let currReport = process.report.getReport().libuv;
2525
const originalReportAddresses = originalReport.map(resource => resource.address);
26-
currReport = currReport.filter(resource =>!originalReportAddresses.includes(resource.address));
26+
currReport = currReport.filter(resource => !originalReportAddresses.includes(resource.address));
2727
return currReport;
2828
}
2929

3030
function log(message) {
3131
// remove outer parentheses for easier parsing
32-
const messageToLog = JSON.stringify(message).slice(1, -1) + ', \n'
32+
const messageToLog = JSON.stringify(message).slice(1, -1) + ', \n';
3333
fs.writeFileSync(logFile, messageToLog, { flag: 'a' });
3434
}
3535

3636
async function main() {
3737
originalReport = process.report.getReport().libuv;
38-
console.log('please');
39-
process.on('beforeExit', code => {
38+
process.on('beforeExit', () => {
4039
log({ beforeExitHappened: true });
4140
});
42-
log({newResources: getNewResourceArray()});
41+
run({ MongoClient, uri });
42+
log({ newResources: getNewResourceArray() });
4343
}
4444

4545
main()
@@ -49,3 +49,11 @@ main()
4949
.catch(() => {
5050
log({ exitCode: 1 });
5151
});
52+
53+
setTimeout(() => {
54+
// this means something was in the event loop such that it hung for more than 10 seconds
55+
// so we kill the process
56+
log({ exitCode : 99 });
57+
process.exit(99);
58+
// using `unref` will ensure this setTimeout call is not a resource / does not keep the event loop running
59+
}, 10000).unref();

0 commit comments

Comments
 (0)