Skip to content

Commit ed5182a

Browse files
authored
test(NODE-5043): assert MongoClients are garbage collectable (#3561)
1 parent 908b3b6 commit ed5182a

File tree

8 files changed

+356
-156
lines changed

8 files changed

+356
-156
lines changed

package-lock.json

Lines changed: 77 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"tsd": "^0.24.1",
7575
"typescript": "^4.8.4",
7676
"typescript-cached-transpile": "^0.0.6",
77+
"v8-heapsnapshot": "^1.2.0",
7778
"xml2js": "^0.4.23",
7879
"yargs": "^17.6.0"
7980
},

test/integration/client-side-encryption/client_side_encryption.prose.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
14221422
expect.fail('it must fail with no tls');
14231423
} catch (e) {
14241424
//Expect an error indicating TLS handshake failed.
1425-
expect(e.originalError.message).to.include('before secure TLS connection');
1425+
expect(e.originalError.message).to.match(/before secure TLS connection|handshake/);
14261426
}
14271427
});
14281428

test/integration/crud/insert.test.js

Lines changed: 24 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,164 +2282,40 @@ describe('crud - insert', function () {
22822282
}
22832283
});
22842284

2285-
it('should return error on unordered insertMany with multiple unique key constraints', {
2286-
// Add a tag that our runner can trigger on
2287-
// in this case we are setting that node needs to be higher than 0.10.X to run
2288-
metadata: {
2289-
requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] }
2290-
},
2285+
it('should return error on unordered insertMany with multiple unique key constraints', async () => {
2286+
const col = client.db().collection('insertManyMultipleWriteErrors');
22912287

2292-
test: function (done) {
2293-
var configuration = this.configuration;
2294-
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
2295-
client.connect(function (err, client) {
2296-
var db = client.db(configuration.db);
2297-
// Get collection
2298-
var col = db.collection('insertManyMultipleWriteErrors');
2299-
col.drop(function (err, r) {
2300-
expect(r).to.not.exist;
2288+
await col.drop().catch(() => null);
23012289

2302-
// Create unique index
2303-
col.createIndex({ a: 1 }, { unique: true }, function (err, r) {
2304-
expect(err).to.not.exist;
2305-
test.ok(r);
2290+
const createIndexRes = await col.createIndex({ a: 1 }, { unique: true });
2291+
expect(createIndexRes).to.equal('a_1');
23062292

2307-
col.insertMany(
2308-
[{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }],
2309-
{ ordered: false },
2310-
function (err, r) {
2311-
expect(r).to.not.exist;
2312-
expect(err).to.exist;
2313-
expect(err.result).to.exist;
2314-
expect(err.result.getWriteErrors()).to.have.length(2);
2293+
const insertManyRes = await col
2294+
.insertMany([{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }], { ordered: false })
2295+
.catch(error => error);
23152296

2316-
client.close(done);
2317-
}
2318-
);
2319-
});
2320-
});
2321-
});
2322-
}
2323-
});
2324-
2325-
it('should return error on unordered insert with multiple unique key constraints', {
2326-
// Add a tag that our runner can trigger on
2327-
// in this case we are setting that node needs to be higher than 0.10.X to run
2328-
metadata: {
2329-
requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] }
2330-
},
2331-
2332-
test: function (done) {
2333-
var configuration = this.configuration;
2334-
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
2335-
client.connect(function (err, client) {
2336-
var db = client.db(configuration.db);
2337-
// Get collection
2338-
var col = db.collection('insertManyMultipleWriteErrors1');
2339-
col.drop(function (err, r) {
2340-
expect(r).to.not.exist;
2341-
2342-
// Create unique index
2343-
col.createIndex({ a: 1 }, { unique: true }, function (err, r) {
2344-
expect(err).to.not.exist;
2345-
test.ok(r);
2346-
2347-
col.insert(
2348-
[{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }],
2349-
{ ordered: false },
2350-
function (err, r) {
2351-
expect(r).to.not.exist;
2352-
expect(err).to.exist;
2353-
expect(err.result).to.exist;
2354-
expect(err.result.getWriteErrors()).to.have.length(2);
2355-
2356-
client.close(done);
2357-
}
2358-
);
2359-
});
2360-
});
2361-
});
2362-
}
2297+
expect(insertManyRes).to.be.instanceOf(MongoBulkWriteError);
2298+
expect(insertManyRes.result).to.exist;
2299+
// Unordered will hit both the a:1 inserts
2300+
expect(insertManyRes.result.getWriteErrors()).to.have.length(2);
23632301
});
23642302

2365-
it('should return error on ordered insertMany with multiple unique key constraints', {
2366-
// Add a tag that our runner can trigger on
2367-
// in this case we are setting that node needs to be higher than 0.10.X to run
2368-
metadata: {
2369-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
2370-
},
2303+
it('should return error on ordered insertMany with multiple unique key constraints', async () => {
2304+
const col = client.db().collection('insertManyMultipleWriteErrors');
23712305

2372-
test: function (done) {
2373-
var configuration = this.configuration;
2374-
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
2375-
client.connect(function (err, client) {
2376-
var db = client.db(configuration.db);
2377-
// Get collection
2378-
var col = db.collection('insertManyMultipleWriteErrors2');
2379-
col.drop(function (/*err, r*/) {
2380-
// TODO: reenable once SERVER-36317 is resolved
2381-
// expect(r).to.not.exist;
2382-
2383-
// Create unique index
2384-
col.createIndex({ a: 1 }, { unique: true }, function (err, r) {
2385-
expect(err).to.not.exist;
2386-
test.ok(r);
2306+
await col.drop().catch(() => null);
23872307

2388-
col.insertMany(
2389-
[{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }],
2390-
{ ordered: true },
2391-
function (err, r) {
2392-
expect(r).to.not.exist;
2393-
test.ok(err != null);
2394-
test.ok(err.result);
2308+
const createIndexRes = await col.createIndex({ a: 1 }, { unique: true });
2309+
expect(createIndexRes).to.equal('a_1');
23952310

2396-
client.close(done);
2397-
}
2398-
);
2399-
});
2400-
});
2401-
});
2402-
}
2403-
});
2311+
const insertManyRes = await col
2312+
.insertMany([{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }], { ordered: true })
2313+
.catch(error => error);
24042314

2405-
it('should return error on ordered insert with multiple unique key constraints', {
2406-
// Add a tag that our runner can trigger on
2407-
// in this case we are setting that node needs to be higher than 0.10.X to run
2408-
metadata: {
2409-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
2410-
},
2411-
2412-
test: function (done) {
2413-
var configuration = this.configuration;
2414-
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
2415-
client.connect(function (err, client) {
2416-
var db = client.db(configuration.db);
2417-
// Get collection
2418-
var col = db.collection('insertManyMultipleWriteErrors3');
2419-
col.drop(function (/*err, r*/) {
2420-
// TODO: reenable once SERVER-36317 is resolved
2421-
// expect(r).to.not.exist;
2422-
2423-
// Create unique index
2424-
col.createIndex({ a: 1 }, { unique: true }, function (err, r) {
2425-
expect(err).to.not.exist;
2426-
test.ok(r);
2427-
2428-
col.insert(
2429-
[{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }],
2430-
{ ordered: true },
2431-
function (err, r) {
2432-
expect(r).to.not.exist;
2433-
test.ok(err != null);
2434-
test.ok(err.result);
2435-
2436-
client.close(done);
2437-
}
2438-
);
2439-
});
2440-
});
2441-
});
2442-
}
2315+
expect(insertManyRes).to.be.instanceOf(MongoBulkWriteError);
2316+
expect(insertManyRes.result).to.exist;
2317+
// Ordered will hit only the second a:1 insert
2318+
expect(insertManyRes.result.getWriteErrors()).to.have.length(1);
24432319
});
24442320

24452321
it('Correctly allow forceServerObjectId for insertOne', {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy