Skip to content

Commit 3338fb9

Browse files
updated tests
delete extraneous files
1 parent 1f321ec commit 3338fb9

File tree

5 files changed

+38
-344
lines changed

5 files changed

+38
-344
lines changed

heartbeat-failed-monitor-timer.cjs

Lines changed: 0 additions & 141 deletions
This file was deleted.

heartbeat-failed-monitor-timer.logs.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

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

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-empty-function */
2-
import { expect } from 'chai';
3-
import * as sinon from 'sinon';
4-
import { Connection, HostAddress, MongoClient } from '../../mongodb';
52
import { type TestConfiguration } from '../../tools/runner/config';
63
import { runScriptAndGetProcessInfo } from './resource_tracking_script_builder';
7-
import { sleep } from '../../tools/utils';
8-
import { ConnectionPool } from '../../mongodb';
9-
import { getActiveResourcesInfo } from 'process';
104

115
describe.only('MongoClient.close() Integration', () => {
126
// note: these tests are set-up in accordance of the resource ownership tree
@@ -342,33 +336,49 @@ describe.only('MongoClient.close() Integration', () => {
342336
describe('Node.js resource: checkOut Timer', () => {
343337
describe('after new connection pool is created', () => {
344338
it('the wait queue timer is cleaned up by client.close()', async function () {
345-
// note: this test is not called in a separate process since it stubs internal class: ConnectionPool
346339
const run = async function ({ MongoClient, uri, expect, sinon, sleep, getTimerCount }) {
347-
const waitQueueTimeoutMS = 999;
348-
const client = new MongoClient(uri, { minPoolSize: 1, waitQueueTimeoutMS });
340+
const waitQueueTimeoutMS = 1515;
341+
342+
// configure failPoint
343+
const utilClient = new MongoClient(uri);
344+
await utilClient.connect();
345+
const failPoint = {
346+
configureFailPoint: 'failCommand',
347+
mode: { times: 1 },
348+
data: { blockConnection: true, blockTimeMS: waitQueueTimeoutMS * 3, failCommands: ['insert'] }
349+
}
350+
await utilClient.db('admin').command(failPoint);
351+
349352
const timers = require('timers');
350353
const timeoutStartedSpy = sinon.spy(timers, 'setTimeout');
351-
let checkoutTimeoutStarted = false;
352-
353-
// make waitQueue hang so check out timer isn't cleared and check that the timeout has started
354-
sinon.stub(ConnectionPool.prototype, 'processWaitQueue').callsFake(async () => {
355-
checkoutTimeoutStarted = timeoutStartedSpy.getCalls().filter(r => r.args.includes(waitQueueTimeoutMS)).flat().length > 0;
356-
});
357354

355+
const client = new MongoClient(uri, { minPoolSize: 1, maxPoolSize: 1, waitQueueTimeoutMS });
358356
const insertPromise = client.db('db').collection('collection').insertOne({ x: 1 }).catch(e => e);
357+
client.db('db').collection('collection').insertOne({ x: 1 }).catch(e => e);
359358

360359
// don't allow entire checkout timer to elapse to ensure close is called mid-timeout
361360
await sleep(waitQueueTimeoutMS / 2);
361+
const checkoutTimeoutStarted = timeoutStartedSpy.getCalls().filter(r => r.args.includes(waitQueueTimeoutMS)).flat().length > 0;
362362
expect(checkoutTimeoutStarted).to.be.true;
363363

364364
await client.close();
365365
expect(getTimerCount()).to.equal(0);
366+
// un-configure fail{oint
367+
await utilClient
368+
.db()
369+
.admin()
370+
.command({
371+
configureFailPoint: 'failCommand',
372+
mode: 'off'
373+
});
374+
375+
await utilClient.close();
366376

367377
const err = await insertPromise;
368-
expect(err).to.not.be.instanceOf(Error);
378+
expect(err).to.be.instanceOf(Error);
379+
expect(err.message).to.contain('Timed out while checking out a connection from connection pool');
369380
};
370-
const getTimerCount = () => process.getActiveResourcesInfo().filter(r => r === 'Timeout').length;
371-
await run({ MongoClient, uri: config.uri, sleep, sinon, expect, getTimerCount});
381+
await runScriptAndGetProcessInfo('timer-check-out', config, run);
372382
});
373383
});
374384
});
@@ -409,43 +419,22 @@ describe.only('MongoClient.close() Integration', () => {
409419

410420
describe('SrvPoller', () => {
411421
describe('Node.js resource: Timer', () => {
412-
// srv polling is not available for load-balanced mode
422+
// requires an srv environment that can transition to sharded
413423
const metadata: MongoDBMetadataUI = {
414424
requires: {
415-
topology: ['single', 'replicaset', 'sharded']
425+
predicate: () => process.env.ATLAS_SRV_REPL ? 'Skipped: this test requires an SRV environment' : true
416426
}
417427
};
428+
418429
describe('after SRVPoller is created', () => {
419430
it.only('timers are cleaned up by client.close()', metadata, async () => {
420-
const run = async function ({ MongoClient, uri, expect, mongodb, sinon, getTimerCount }) {
421-
const dns = require('dns');
422-
sinon.stub(dns.promises, 'resolveTxt').callsFake(async () => {
423-
throw { code: 'ENODATA' };
424-
});
425-
sinon.stub(dns.promises, 'resolveSrv').callsFake(async () => {
426-
return [
427-
{
428-
name: 'domain.localhost',
429-
port: 27017,
430-
weight: 0,
431-
priority: 0,
432-
protocol: 'IPv6'
433-
}
434-
];
435-
});
436-
437-
const client = new MongoClient('mongodb+srv://localhost');
438-
client.connect();
439-
440-
const topology = client.topology;
441-
const prevDesc = topology;
442-
log({ topology });
443-
const currDesc = prevDesc;
444-
client.topology.emit(
445-
'topologyDescriptionChanged',
446-
mongodb.TopologyDescriptionChangedEvent(client.topology.s.id, prevDesc, currDesc)
447-
);
448-
431+
const run = async function ({ MongoClient, uri, expect, sinon, getTimerCount }) {
432+
const client = new MongoClient(uri);
433+
await client.connect();
434+
const description = client.topology.s.description;
435+
// simulate transition to sharded
436+
client.topology.emit('topologyDescriptionChanged', description, { ... description, type: 'Sharded'});
437+
expect(client.topology.s.srvPoller?._timeout).to.exist;
449438
await client.close();
450439
expect(getTimerCount()).to.equal(0);
451440
};

0 commit comments

Comments
 (0)