Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(NODE-6620): client.close() interrupts file reads #4355

Merged
merged 30 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0af55e9
skeleton
aditi-khare-mongoDB Dec 16, 2024
4798bc2
skeleton updates
aditi-khare-mongoDB Dec 16, 2024
8adca00
refactor for table
aditi-khare-mongoDB Dec 17, 2024
3412bb1
boilerplate execution
aditi-khare-mongoDB Dec 17, 2024
1531bec
fix
aditi-khare-mongoDB Dec 17, 2024
4200f3f
preliminary tests finished
aditi-khare-mongoDB Dec 18, 2024
321ef71
remove misc file
aditi-khare-mongoDB Dec 18, 2024
1503084
temp for screen-share
aditi-khare-mongoDB Dec 19, 2024
a128974
lint
aditi-khare-mongoDB Dec 19, 2024
4e55dee
boilerplate fully working
aditi-khare-mongoDB Dec 19, 2024
f560088
TLS test case running
aditi-khare-mongoDB Dec 20, 2024
ef9cc90
clea up lint
aditi-khare-mongoDB Dec 20, 2024
9ed1528
clean up
aditi-khare-mongoDB Dec 20, 2024
1c8e20f
most of tree reformatting done
aditi-khare-mongoDB Dec 20, 2024
1de9809
reorganized tests and added in most of neal's suggestions
aditi-khare-mongoDB Dec 20, 2024
e77405f
TLS test cases and socket test cases
aditi-khare-mongoDB Dec 30, 2024
11aa73c
TLS test cases
aditi-khare-mongoDB Dec 30, 2024
c99579a
fix message formatting
aditi-khare-mongoDB Dec 30, 2024
1aeb046
Merge branch 'main' into NODE-6615/integration-client-close
aditi-khare-mongoDB Dec 30, 2024
47c20db
fix message formatting + test cases naming
aditi-khare-mongoDB Dec 30, 2024
133b20d
Delete logs.txt
aditi-khare-mongoDB Dec 30, 2024
8fd53a4
requested changes: remove log calls, change chai to expect, clarify s…
aditi-khare-mongoDB Dec 30, 2024
e60a42b
requested changes: additional expectation
aditi-khare-mongoDB Dec 30, 2024
d9ed22a
removed resources that we are no longer integration testing - connect…
aditi-khare-mongoDB Jan 2, 2025
83b5685
requested changes: add in exitCode message, skip unimplemented tests,…
aditi-khare-mongoDB Jan 2, 2025
454859e
requested changes: fix exitCode
aditi-khare-mongoDB Jan 2, 2025
5eb92ee
neal's requested changes
aditi-khare-mongoDB Jan 3, 2025
77fadbb
re-add assertion
aditi-khare-mongoDB Jan 5, 2025
aefa1cc
Update test/integration/node-specific/resource_tracking_script_builde…
aditi-khare-mongoDB Jan 6, 2025
e9a3108
make stderr inherit
aditi-khare-mongoDB Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions test/integration/node-specific/client_close.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-empty-function */

import { type TestConfiguration } from '../../tools/runner/config';
import { runScriptAndGetProcessInfo } from './resource_tracking_script_builder';

Expand All @@ -20,12 +19,14 @@ describe.skip('MongoClient.close() Integration', () => {
config,
async function run({ MongoClient, uri, expect }) {
const infiniteFile = '/dev/zero';
const client = new MongoClient(uri, { tlsCertificateKeyFile: infiniteFile });
client.connect();
const client = new MongoClient(uri, { tls: true, tlsCertificateKeyFile: infiniteFile });
const connectPromise = client.connect();
expect(process.getActiveResourcesInfo()).to.include('FSReqPromise');
await client.close();
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
expect(process.getActiveResourcesInfo()).to.not.include('FSReqPromise');
}
const err = await connectPromise.catch(e => e);
expect(err).to.exist;
}
);
});
});
Expand Down Expand Up @@ -74,7 +75,7 @@ describe.skip('MongoClient.close() Integration', () => {
describe('Topology', () => {
describe('Node.js resource: Server Selection Timer', () => {
describe('after a Topology is created through client.connect()', () => {
it('server selection timers are cleaned up by client.close()', async () => {});
it.skip('server selection timers are cleaned up by client.close()', async () => {});
});
});

Expand All @@ -90,25 +91,25 @@ describe.skip('MongoClient.close() Integration', () => {
describe('MonitorInterval', () => {
describe('Node.js resource: Timer', () => {
describe('after a new monitor is made', () => {
it('monitor interval timer is cleaned up by client.close()', async () => {});
it.skip('monitor interval timer is cleaned up by client.close()', async () => {});
});

describe('after a heartbeat fails', () => {
it('the new monitor interval timer is cleaned up by client.close()', async () => {});
it.skip('the new monitor interval timer is cleaned up by client.close()', async () => {});
});
});
});

describe('Connection Monitoring', () => {
describe('Node.js resource: Socket', () => {
it('no sockets remain after client.close()', metadata, async function () {});
it.skip('no sockets remain after client.close()', metadata, async function () {});
});
});

describe('RTT Pinger', () => {
describe('Node.js resource: Timer', () => {
describe('after entering monitor streaming mode ', () => {
it('the rtt pinger timer is cleaned up by client.close()', async () => {
it.skip('the rtt pinger timer is cleaned up by client.close()', async () => {
// helloReply has a topologyVersion defined
});
});
Expand All @@ -117,7 +118,7 @@ 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()', async () => {});
it.skip('no sockets remain after client.close()', async () => {});
});
});
});
Expand All @@ -127,25 +128,25 @@ describe.skip('MongoClient.close() Integration', () => {
describe('ConnectionPool', () => {
describe('Node.js resource: minPoolSize timer', () => {
describe('after new connection pool is created', () => {
it('the minPoolSize timer is cleaned up by client.close()', async () => {});
it.skip('the minPoolSize timer is cleaned up by client.close()', async () => {});
});
});

describe('Node.js resource: checkOut Timer', () => {
// waitQueueTimeoutMS
describe('after new connection pool is created', () => {
it('the wait queue timer is cleaned up by client.close()', async () => {});
it.skip('the wait queue timer is cleaned up by client.close()', async () => {});
});
});

describe('Connection', () => {
describe('Node.js resource: Socket', () => {
describe('after a connection is checked out', () => {
it('no sockets remain after client.close()', async () => {});
it.skip('no sockets remain after client.close()', async () => {});
});

describe('after a minPoolSize has been set on the ConnectionPool', () => {
it('no sockets remain after client.close()', async () => {});
it.skip('no sockets remain after client.close()', async () => {});
});
});
});
Expand All @@ -155,7 +156,7 @@ describe.skip('MongoClient.close() Integration', () => {
describe('SrvPoller', () => {
describe('Node.js resource: Timer', () => {
describe('after SRVPoller is created', () => {
it('timers are cleaned up by client.close()', async () => {});
it.skip('timers are cleaned up by client.close()', async () => {});
});
});
});
Expand All @@ -164,27 +165,27 @@ describe.skip('MongoClient.close() Integration', () => {
describe('ClientSession (Implicit)', () => {
describe('Server resource: LSID/ServerSession', () => {
describe('after a clientSession is implicitly created and used', () => {
it('the server-side ServerSession is cleaned up by client.close()', async function () {});
it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {});
});
});

describe('Server resource: Transactions', () => {
describe('after a clientSession is implicitly created and used', () => {
it('the server-side transaction is cleaned up by client.close()', async function () {});
it.skip('the server-side transaction is cleaned up by client.close()', async function () {});
});
});
});

describe('ClientSession (Explicit)', () => {
describe('Server resource: LSID/ServerSession', () => {
describe('after a clientSession is created and used', () => {
it('the server-side ServerSession is cleaned up by client.close()', async function () {});
it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {});
});
});

describe('Server resource: Transactions', () => {
describe('after a clientSession is created and used', () => {
it('the server-side transaction is cleaned up by client.close()', async function () {});
it.skip('the server-side transaction is cleaned up by client.close()', async function () {});
});
});
});
Expand Down Expand Up @@ -287,14 +288,14 @@ describe.skip('MongoClient.close() Integration', () => {
});

describe('Node.js resource: Socket', () => {
it('no sockets remain after client.close()', metadata, async () => {});
it.skip('no sockets remain after client.close()', metadata, async () => {});
});
});
});

describe('Server resource: Cursor', () => {
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
describe('after cursors are created', () => {
it('all active server-side cursors are closed by client.close()', async function () {});
it.skip('all active server-side cursors are closed by client.close()', async function () {});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { on, once } from 'node:events';
import { readFile, unlink, writeFile } from 'node:fs/promises';
import * as path from 'node:path';

import { expect } from 'chai';
import { AssertionError, expect } from 'chai';
import { parseSnapshot } from 'v8-heapsnapshot';

import { type BSON, type ClientEncryption, type MongoClient } from '../../mongodb';
Expand Down Expand Up @@ -187,7 +187,11 @@ export async function runScriptAndGetProcessInfo(
await unlink(logFile);

// assertions about exit status
expect(exitCode, 'process should have exited with zero').to.equal(0);
if (exitCode) {
const assertionError = new AssertionError(messages.error.message);
assertionError.stack = messages.error.stack + new Error().stack.slice('Error'.length);
throw assertionError;
}

// assertions about resource status
expect(messages.beforeExitHappened).to.be.true;
Expand Down
4 changes: 3 additions & 1 deletion test/tools/fixtures/process_resource_script.in.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ async function main() {
main()
.then(() => {})
.catch(e => {
log({ exitCode: 1, error: util.inspect(e) });
log({ exitCode: 1, error: { message: e.message, stack: e.stack } });
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
});

setTimeout(() => {
// this means something was in the event loop such that it hung for more than 10 seconds
// so we kill the process
log({ newLibuvResources: getNewLibuvResourceArray() });
log({ exitCode: 99, error: { message: 'Process timed out: resources remain in the event loop.' } });
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
process.exit(99);
// using `unref` will ensure this setTimeout call is not a resource / does not keep the event loop running
}, 10000).unref();
Loading