Skip to content

Commit b90bcc9

Browse files
committed
fix: leaks!
1 parent 6d49b23 commit b90bcc9

File tree

15 files changed

+54
-141
lines changed

15 files changed

+54
-141
lines changed

test/integration/collation/collations.test.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ describe('Collation', function () {
2828
await client.close();
2929
});
3030

31-
/******************************************************************************
32-
.___ __ __ .__
33-
| | _____/ |_ ____ ________________ _/ |_|__| ____ ____
34-
| |/ \ __\/ __ \ / ___\_ __ \__ \\ __\ |/ _ \ / \
35-
| | | \ | \ ___// /_/ > | \// __ \| | | ( <_> ) | \
36-
|___|___| /__| \___ >___ /|__| (____ /__| |__|\____/|___| /
37-
\/ \/_____/ \/ \/
38-
******************************************************************************/
3931
it('Should correctly create index with collation', async function () {
4032
const configuration = this.configuration;
4133
const client = configuration.newClient();

test/integration/command-monitoring/command_monitoring.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect } from 'chai';
33
import { ReadPreference } from '../../../src/read_preference';
44
import { filterForCommands, ignoreNsNotFound, setupDatabase } from '../shared';
55

6-
describe('APM', function () {
6+
describe('Command Monitoring', function () {
77
before(function () {
88
return setupDatabase(this.configuration);
99
});

test/integration/connection-monitoring-and-pooling/connection.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22

3-
import { MongoClient, ServerHeartbeatStartedEvent } from '../../../src';
3+
import { MongoClient, MongoServerError, ServerHeartbeatStartedEvent } from '../../../src';
44
import { connect } from '../../../src/cmap/connect';
55
import { Connection } from '../../../src/cmap/connection';
66
import { LEGACY_HELLO_COMMAND } from '../../../src/constants';

test/integration/crud/bulk.test.ts

Lines changed: 30 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ describe('Bulk', function () {
2020
beforeEach(async function () {
2121
client = this.configuration.newClient({}, { maxPoolSize: 1, monitorCommands: true });
2222

23-
// TODO(NODE-4192): Not all operations support auto connect
24-
await client.db().command({ ping: 1 });
25-
2623
client.s.options.dbName = DB_NAME; // make default for client.db() calls
2724
await client
2825
.db(DB_NAME)
@@ -242,9 +239,6 @@ describe('Bulk', function () {
242239
const db = client.db('shouldInheritPromoteLongFalseFromDb1', { promoteLongs: false });
243240
const coll = db.collection<{ a: Long }>('test');
244241

245-
// TODO(NODE-4192): Not all operations support auto connect
246-
await client.db().command({ ping: 1 });
247-
248242
const batch = coll.initializeUnorderedBulkOp();
249243
batch.insert({ a: Long.fromNumber(10) });
250244
const result = await batch.execute();
@@ -285,9 +279,6 @@ describe('Bulk', function () {
285279
});
286280

287281
it('should inherit promote long false from collection during ordered bulk operation', async function () {
288-
// TODO(NODE-4192): Not all operations support auto connect
289-
await client.db().command({ ping: 1 });
290-
291282
const db = client.db('shouldInheritPromoteLongFalseFromColl2', { promoteLongs: true });
292283
const coll = db.collection('test', { promoteLongs: false });
293284

@@ -1345,11 +1336,10 @@ describe('Bulk', function () {
13451336

13461337
it('should return an error instead of throwing when an empty bulk operation is submitted (with promise)', function () {
13471338
return client
1348-
.connect()
1349-
.then(function () {
1350-
const db = client.db();
1351-
return db.collection('doesnt_matter').insertMany([]);
1352-
})
1339+
.db()
1340+
.collection('doesnt_matter')
1341+
.insertMany([])
1342+
13531343
.then(function () {
13541344
test.equal(false, true); // this should not happen!
13551345
})
@@ -1359,61 +1349,44 @@ describe('Bulk', function () {
13591349
});
13601350
});
13611351

1362-
it('should properly account for array key size in bulk unordered inserts', function (done) {
1352+
it('should properly account for array key size in bulk unordered inserts', function () {
13631353
const documents = new Array(20000).fill('').map(() => ({
13641354
arr: new Array(19).fill('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
13651355
}));
13661356

1367-
let db;
1368-
1369-
client
1370-
.connect()
1371-
// NOTE: Hack to get around unrelated strange error in bulkWrites for right now.
1372-
.then(() => {
1373-
db = client.db();
1374-
return db.dropCollection('doesnt_matter').catch(() => {
1375-
// ignore
1376-
});
1357+
// NOTE: Hack to get around unrelated strange error in bulkWrites for right now.
1358+
return client
1359+
.db()
1360+
.dropCollection('doesnt_matter')
1361+
.catch(() => {
1362+
// ignore
13771363
})
13781364
.then(() => {
1379-
return db.createCollection('doesnt_matter');
1365+
return client.db().createCollection('doesnt_matter');
13801366
})
13811367
.then(() => {
1382-
const coll = db.collection('doesnt_matter');
1383-
1384-
coll.insertMany(documents, { ordered: false }, err => {
1385-
done(err);
1386-
});
1368+
const coll = client.db().collection('doesnt_matter');
1369+
return coll.insertMany(documents, { ordered: false });
13871370
});
13881371
});
13891372

1390-
it('should properly account for array key size in bulk ordered inserts', function (done) {
1373+
it('should properly account for array key size in bulk ordered inserts', function () {
13911374
const documents = new Array(20000).fill('').map(() => ({
13921375
arr: new Array(19).fill('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
13931376
}));
13941377

1395-
let db;
1396-
1397-
client
1398-
.connect()
1399-
// NOTE: Hack to get around unrelated strange error in bulkWrites for right now.
1400-
.then(() => {
1401-
db = client.db();
1402-
return db.dropCollection('doesnt_matter').catch(() => {
1403-
// ignore
1404-
});
1378+
return client
1379+
.db()
1380+
.dropCollection('doesnt_matter')
1381+
.catch(() => {
1382+
// ignore
14051383
})
14061384
.then(() => {
1407-
return db.createCollection('doesnt_matter');
1385+
return client.db().createCollection('doesnt_matter');
14081386
})
14091387
.then(() => {
1410-
const coll = db.collection('doesnt_matter');
1411-
1412-
coll.insertMany(documents, { ordered: true }, err => {
1413-
client.close(() => {
1414-
done(err);
1415-
});
1416-
});
1388+
const coll = client.db().collection('doesnt_matter');
1389+
return coll.insertMany(documents, { ordered: true });
14171390
});
14181391
});
14191392

@@ -1463,7 +1436,8 @@ describe('Bulk', function () {
14631436
.then(() => {
14641437
const coll = db.collection('doesnt_matter');
14651438
return coll.insertMany(documents, { ordered: false });
1466-
});
1439+
})
1440+
.finally(() => client.close());
14671441
});
14681442

14691443
function testPropagationOfBulkWriteError(bulk) {
@@ -1477,11 +1451,11 @@ describe('Bulk', function () {
14771451
);
14781452
}
14791453

1480-
it('should propagate the proper error from executing an empty ordered batch', function () {
1481-
return client.connect().then(() => {
1482-
const collection = client.db().collection('doesnt_matter');
1483-
return testPropagationOfBulkWriteError(collection.initializeOrderedBulkOp());
1484-
});
1454+
it('should propagate the proper error from executing an empty ordered batch', async function () {
1455+
await client.connect();
1456+
const collection = client.db().collection('doesnt_matter');
1457+
await testPropagationOfBulkWriteError(collection.initializeOrderedBulkOp());
1458+
await client.close();
14851459
});
14861460

14871461
it('should propagate the proper error from executing an empty unordered batch', function () {
@@ -1788,14 +1762,9 @@ describe('Bulk', function () {
17881762
});
17891763

17901764
describe('Bulk operation transaction rollback', () => {
1791-
let client: MongoClient;
17921765
let collection: Collection<{ answer: number }>;
17931766

17941767
beforeEach(async function () {
1795-
const config = this.configuration;
1796-
client = config.newClient();
1797-
await client.connect();
1798-
17991768
try {
18001769
await client
18011770
.db('bulk_operation_writes_test')
@@ -1812,10 +1781,6 @@ describe('Bulk', function () {
18121781
await collection.deleteMany({});
18131782
});
18141783

1815-
afterEach(async () => {
1816-
if (client) await client.close();
1817-
});
1818-
18191784
it('should abort ordered bulk operation writes', {
18201785
metadata: { requires: { mongodb: '>= 4.2', topology: ['replicaset'] } },
18211786
async test() {

test/integration/crud/bulk_execute_operation.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ describe('Bulk executeOperation', () => {
1414
it('should use the same session for every operation', async () => {
1515
const collection = client.db().collection('bulk_execute_operation');
1616

17-
// TODO(NODE-4192): Not all operations support auto connect
17+
// TODO(NODE-4263): Legacy bulk operations require connecting invocation
1818
await client.db().command({ ping: 1 });
19+
1920
const batch = collection.initializeOrderedBulkOp();
2021

2122
const events = [];

test/integration/crud/crud_api.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ describe('CRUD API', function () {
3838
.db(DB_NAME)
3939
.dropDatabase()
4040
.catch(() => null);
41+
42+
await cleanup.close();
4143
});
4244

4345
it('should correctly execute findOne method using crud api', async function () {

test/integration/crud/find_cursor_methods.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ describe('Find Cursor', function () {
1717

1818
beforeEach(async function () {
1919
client = this.configuration.newClient({ monitorCommands: true });
20-
// TODO(NODE-4262): fix session needing connection
21-
await client.db().command({ ping: 1 });
2220
});
2321
afterEach(async function () {
2422
await client.close();

test/integration/crud/insert.test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ const ISODate = function (string) {
6262
};
6363

6464
describe('crud - insert', function () {
65-
before(function () {
66-
return setupDatabase(this.configuration);
65+
let client;
66+
beforeEach(async function () {
67+
client = this.configuration.newClient();
68+
});
69+
70+
afterEach(async function () {
71+
await client.close();
6772
});
6873

6974
context('insert promise tests', () => {
@@ -1954,7 +1959,6 @@ describe('crud - insert', function () {
19541959
},
19551960

19561961
test: async function () {
1957-
const client = this.configuration.newClient();
19581962
const db = client.db('shouldCorrectlyInheritPromoteLongFalseNativeBSONWithGetMore', {
19591963
promoteLongs: true
19601964
});
@@ -2587,7 +2591,6 @@ describe('crud - insert', function () {
25872591
});
25882592

25892593
it('MongoBulkWriteError and BulkWriteResult should respect BulkWrite', function () {
2590-
const client = this.configuration.newClient();
25912594
return client
25922595
.connect()
25932596
.then(() => {

test/integration/crud/misc_cursors.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const { setTimeout } = require('timers');
1212
const { ReadPreference } = require('../../../src/read_preference');
1313
const { ServerType } = require('../../../src/sdam/common');
1414
const { formatSort } = require('../../../src/sort');
15+
const { getSymbolFrom } = require('../../tools/utils');
1516

1617
describe('Cursor', function () {
1718
before(function () {

test/integration/objectid.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { expect } = require('chai');
44
var setupDatabase = require('./shared').setupDatabase;
55
const { ObjectId } = require('../../src');
66
const { setInterval } = require('timers');
7+
const { sleep } = require('../tools/utils');
78

89
describe('ObjectId', function () {
910
before(function () {

test/integration/server-discovery-and-monitoring/topology_description.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ describe('TopologyDescription (integration tests)', function () {
3535
let client: MongoClient;
3636
beforeEach(async function () {
3737
client = this.configuration.newClient();
38-
await client.db().command({ ping: 1 });
3938
});
4039

4140
afterEach(async function () {
@@ -55,6 +54,7 @@ describe('TopologyDescription (integration tests)', function () {
5554
`when running against ${filterType} driver should declare ${driverType} topology type`,
5655
{ requires: { topology: filterType } },
5756
async () => {
57+
await client.db().command({ ping: 1 });
5858
expect(client.topology).to.exist;
5959
expect(client.topology.description).to.exist;
6060
expect(client.topology.description).to.have.property('type', driverType);

test/integration/sessions/sessions.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ describe('Sessions Spec', function () {
225225
}
226226
});
227227

228-
await client.db().command({ ping: 1 });
229228
const session = client.startSession({ causalConsistency: true });
230229

231230
const error = await client

test/tools/runner/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class TestConfiguration {
5151
version: string;
5252
clientSideEncryption: Record<string, any>;
5353
/** null means topology does not support command (serverless) */
54-
parameters: Record<string, any> | null;
54+
parameters: Record<string, any>;
5555
singleMongosLoadBalancerUri: string;
5656
multiMongosLoadBalancerUri: string;
5757
isServerless: boolean;
@@ -77,7 +77,7 @@ export class TestConfiguration {
7777
const hostAddresses = hosts.map(HostAddress.fromString);
7878
this.version = context.version;
7979
this.clientSideEncryption = context.clientSideEncryption;
80-
this.parameters = null;
80+
this.parameters = { ...context.parameters };
8181
this.singleMongosLoadBalancerUri = context.singleMongosLoadBalancerUri;
8282
this.multiMongosLoadBalancerUri = context.multiMongosLoadBalancerUri;
8383
this.isServerless = !!process.env.SERVERLESS;

test/tools/runner/hooks/configuration.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,17 @@ const testConfigBeforeHook = async function () {
115115
context.multiMongosLoadBalancerUri = MULTI_MONGOS_LB_URI;
116116
}
117117

118+
context.parameters = await client
119+
.db()
120+
.admin()
121+
.command({ getParameter: '*' })
122+
.catch(error => ({ noReply: error }));
123+
118124
this.configuration = new TestConfiguration(
119125
loadBalanced ? SINGLE_MONGOS_LB_URI : MONGODB_URI,
120126
context
121127
);
122128

123-
this.configuration.parameters = await client
124-
.db()
125-
.admin()
126-
.command({ getParameter: '*' })
127-
.catch(() => null);
128-
129129
await client.close();
130130

131131
const currentEnv = {

0 commit comments

Comments
 (0)