Skip to content

Commit

Permalink
test(NODE-5043): assert MongoClients are garbage collectable (#3561)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken authored Feb 13, 2023
1 parent 908b3b6 commit ed5182a
Show file tree
Hide file tree
Showing 8 changed files with 356 additions and 156 deletions.
83 changes: 77 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"tsd": "^0.24.1",
"typescript": "^4.8.4",
"typescript-cached-transpile": "^0.0.6",
"v8-heapsnapshot": "^1.2.0",
"xml2js": "^0.4.23",
"yargs": "^17.6.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
expect.fail('it must fail with no tls');
} catch (e) {
//Expect an error indicating TLS handshake failed.
expect(e.originalError.message).to.include('before secure TLS connection');
expect(e.originalError.message).to.match(/before secure TLS connection|handshake/);
}
});

Expand Down
172 changes: 24 additions & 148 deletions test/integration/crud/insert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2282,164 +2282,40 @@ describe('crud - insert', function () {
}
});

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

test: function (done) {
var configuration = this.configuration;
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
client.connect(function (err, client) {
var db = client.db(configuration.db);
// Get collection
var col = db.collection('insertManyMultipleWriteErrors');
col.drop(function (err, r) {
expect(r).to.not.exist;
await col.drop().catch(() => null);

// Create unique index
col.createIndex({ a: 1 }, { unique: true }, function (err, r) {
expect(err).to.not.exist;
test.ok(r);
const createIndexRes = await col.createIndex({ a: 1 }, { unique: true });
expect(createIndexRes).to.equal('a_1');

col.insertMany(
[{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }],
{ ordered: false },
function (err, r) {
expect(r).to.not.exist;
expect(err).to.exist;
expect(err.result).to.exist;
expect(err.result.getWriteErrors()).to.have.length(2);
const insertManyRes = await col
.insertMany([{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }], { ordered: false })
.catch(error => error);

client.close(done);
}
);
});
});
});
}
});

it('should return error on unordered insert with multiple unique key constraints', {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: {
requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] }
},

test: function (done) {
var configuration = this.configuration;
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
client.connect(function (err, client) {
var db = client.db(configuration.db);
// Get collection
var col = db.collection('insertManyMultipleWriteErrors1');
col.drop(function (err, r) {
expect(r).to.not.exist;

// Create unique index
col.createIndex({ a: 1 }, { unique: true }, function (err, r) {
expect(err).to.not.exist;
test.ok(r);

col.insert(
[{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }],
{ ordered: false },
function (err, r) {
expect(r).to.not.exist;
expect(err).to.exist;
expect(err.result).to.exist;
expect(err.result.getWriteErrors()).to.have.length(2);

client.close(done);
}
);
});
});
});
}
expect(insertManyRes).to.be.instanceOf(MongoBulkWriteError);
expect(insertManyRes.result).to.exist;
// Unordered will hit both the a:1 inserts
expect(insertManyRes.result.getWriteErrors()).to.have.length(2);
});

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

test: function (done) {
var configuration = this.configuration;
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
client.connect(function (err, client) {
var db = client.db(configuration.db);
// Get collection
var col = db.collection('insertManyMultipleWriteErrors2');
col.drop(function (/*err, r*/) {
// TODO: reenable once SERVER-36317 is resolved
// expect(r).to.not.exist;

// Create unique index
col.createIndex({ a: 1 }, { unique: true }, function (err, r) {
expect(err).to.not.exist;
test.ok(r);
await col.drop().catch(() => null);

col.insertMany(
[{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }],
{ ordered: true },
function (err, r) {
expect(r).to.not.exist;
test.ok(err != null);
test.ok(err.result);
const createIndexRes = await col.createIndex({ a: 1 }, { unique: true });
expect(createIndexRes).to.equal('a_1');

client.close(done);
}
);
});
});
});
}
});
const insertManyRes = await col
.insertMany([{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }], { ordered: true })
.catch(error => error);

it('should return error on ordered insert with multiple unique key constraints', {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
},

test: function (done) {
var configuration = this.configuration;
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
client.connect(function (err, client) {
var db = client.db(configuration.db);
// Get collection
var col = db.collection('insertManyMultipleWriteErrors3');
col.drop(function (/*err, r*/) {
// TODO: reenable once SERVER-36317 is resolved
// expect(r).to.not.exist;

// Create unique index
col.createIndex({ a: 1 }, { unique: true }, function (err, r) {
expect(err).to.not.exist;
test.ok(r);

col.insert(
[{ a: 1 }, { a: 2 }, { a: 1 }, { a: 3 }, { a: 1 }],
{ ordered: true },
function (err, r) {
expect(r).to.not.exist;
test.ok(err != null);
test.ok(err.result);

client.close(done);
}
);
});
});
});
}
expect(insertManyRes).to.be.instanceOf(MongoBulkWriteError);
expect(insertManyRes.result).to.exist;
// Ordered will hit only the second a:1 insert
expect(insertManyRes.result.getWriteErrors()).to.have.length(1);
});

it('Correctly allow forceServerObjectId for insertOne', {
Expand Down
Loading

0 comments on commit ed5182a

Please sign in to comment.