Skip to content

Commit 7a8efc7

Browse files
committed
fix self references in bulk
1 parent d36b497 commit 7a8efc7

File tree

2 files changed

+58
-67
lines changed

2 files changed

+58
-67
lines changed

test/integration/crud/bulk.test.ts

Lines changed: 56 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ describe('Bulk', function () {
1818
let client: MongoClient;
1919

2020
beforeEach(async function () {
21-
client = this.configuration.newClient(this.configuration.writeConcernMax(), {
22-
maxPoolSize: 1,
23-
monitorCommands: true
24-
});
21+
client = this.configuration.newClient({}, { maxPoolSize: 1, monitorCommands: true });
2522

2623
// TODO(NODE-4192): Not all operations support auto connect
2724
await client.db().command({ ping: 1 });
@@ -498,7 +495,7 @@ describe('Bulk', function () {
498495
},
499496

500497
test: function (done) {
501-
client.connect(function (err, client) {
498+
client.connect((err, client) => {
502499
const db = client.db();
503500
const col = db.collection('batch_write_ordered_ops_8');
504501
const batch = col.initializeOrderedBulkOp();
@@ -536,7 +533,7 @@ describe('Bulk', function () {
536533
},
537534

538535
test: function (done) {
539-
client.connect(function (err, client) {
536+
client.connect((err, client) => {
540537
const db = client.db();
541538
const col = db.collection('batch_write_ordered_ops_8');
542539

@@ -551,7 +548,7 @@ describe('Bulk', function () {
551548
});
552549

553550
it('should correctly execute ordered batch using w:0', function (done) {
554-
client.connect(function (err, client) {
551+
client.connect((err, client) => {
555552
const db = client.db();
556553
const col = db.collection('batch_write_ordered_ops_9');
557554

@@ -578,7 +575,7 @@ describe('Bulk', function () {
578575
});
579576

580577
it('should correctly handle single unordered batch API', function (done) {
581-
client.connect(function (err, client) {
578+
client.connect((err, client) => {
582579
const db = client.db();
583580
const col = db.collection('batch_write_unordered_ops_legacy_1');
584581

@@ -680,7 +677,7 @@ describe('Bulk', function () {
680677
metadata: { requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] } },
681678

682679
test: function (done) {
683-
client.connect(function (err, client) {
680+
client.connect((err, client) => {
684681
const db = client.db();
685682
const coll = db.collection('batch_write_unordered_ops_legacy_3');
686683
// Set up a giant string to blow through the max message size
@@ -709,7 +706,7 @@ describe('Bulk', function () {
709706
metadata: { requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] } },
710707

711708
test: function (done) {
712-
client.connect(function (err, client) {
709+
client.connect((err, client) => {
713710
const db = client.db();
714711
const coll = db.collection('batch_write_unordered_ops_legacy_4');
715712

@@ -743,12 +740,12 @@ describe('Bulk', function () {
743740
});
744741

745742
it('should Correctly Execute Unordered Batch with duplicate key errors on updates', function (done) {
746-
client.connect(function (err, client) {
743+
client.connect((err, client) => {
747744
const db = client.db();
748745
const col = db.collection('batch_write_unordered_ops_legacy_6');
749746

750747
// Write concern
751-
const writeConcern = self.configuration.writeConcernMax();
748+
const writeConcern = this.configuration.writeConcernMax();
752749
writeConcern.unique = true;
753750
writeConcern.sparse = false;
754751

@@ -768,7 +765,7 @@ describe('Bulk', function () {
768765
batch.insert({ b: 1 });
769766

770767
// Execute the operations
771-
batch.execute(self.configuration.writeConcernMax(), function (err, result) {
768+
batch.execute({}, function (err, result) {
772769
expect(err).to.exist;
773770
expect(result).to.not.exist;
774771

@@ -845,12 +842,12 @@ describe('Bulk', function () {
845842
metadata: { requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] } },
846843

847844
test: function (done) {
848-
client.connect(function (err, client) {
845+
client.connect((err, client) => {
849846
const db = client.db();
850847
const col = db.collection('batch_write_unordered_ops_legacy_7');
851848

852849
// Add unique index on b field causing all updates to fail
853-
col.createIndex({ b: 1 }, { unique: true, sparse: false }, function (err) {
850+
col.createIndex({ b: 1 }, { unique: true, sparse: false }, err => {
854851
expect(err).to.not.exist;
855852

856853
// Initialize the unordered Batch
@@ -871,7 +868,7 @@ describe('Bulk', function () {
871868
batch.insert({ b: 1 });
872869

873870
// Execute the operations
874-
batch.execute(self.configuration.writeConcernMax(), function (err, result) {
871+
batch.execute({}, function (err, result) {
875872
expect(err).to.exist;
876873
expect(result).to.not.exist;
877874

@@ -906,47 +903,43 @@ describe('Bulk', function () {
906903
}
907904
);
908905

909-
it('should correctly perform unordered upsert with custom _id', {
910-
metadata: { requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] } },
911-
912-
test: function (done) {
913-
client.connect(function (err, client) {
914-
const db = client.db();
915-
const col = db.collection('batch_write_unordered_ops_legacy_8');
916-
const batch = col.initializeUnorderedBulkOp();
906+
it('should correctly perform unordered upsert with custom _id', function (done) {
907+
client.connect((err, client) => {
908+
const db = client.db();
909+
const col = db.collection('batch_write_unordered_ops_legacy_8');
910+
const batch = col.initializeUnorderedBulkOp();
917911

918-
// Add some operations to be executed in order
919-
batch
920-
.find({ _id: 2 })
921-
.upsert()
922-
.updateOne({ $set: { b: 2 } });
912+
// Add some operations to be executed in order
913+
batch
914+
.find({ _id: 2 })
915+
.upsert()
916+
.updateOne({ $set: { b: 2 } });
923917

924-
// Execute the operations
925-
batch.execute(self.configuration.writeConcernMax(), function (err, result) {
926-
// Check state of result
927-
test.equal(1, result.nUpserted);
928-
test.equal(0, result.nInserted);
929-
test.equal(0, result.nMatched);
930-
test.ok(0 === result.nModified || result.nModified == null);
931-
test.equal(0, result.nRemoved);
918+
// Execute the operations
919+
batch.execute({}, function (err, result) {
920+
// Check state of result
921+
test.equal(1, result.nUpserted);
922+
test.equal(0, result.nInserted);
923+
test.equal(0, result.nMatched);
924+
test.ok(0 === result.nModified || result.nModified == null);
925+
test.equal(0, result.nRemoved);
932926

933-
const upserts = result.getUpsertedIds();
934-
test.equal(1, upserts.length);
935-
test.equal(0, upserts[0].index);
936-
test.equal(2, upserts[0]._id);
927+
const upserts = result.getUpsertedIds();
928+
test.equal(1, upserts.length);
929+
test.equal(0, upserts[0].index);
930+
test.equal(2, upserts[0]._id);
937931

938-
// Finish up test
939-
client.close(done);
940-
});
932+
// Finish up test
933+
client.close(done);
941934
});
942-
}
935+
});
943936
});
944937

945938
it('should prohibit batch finds with no selector', {
946939
metadata: { requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] } },
947940

948941
test: function (done) {
949-
client.connect(function (err, client) {
942+
client.connect((err, client) => {
950943
expect(err).to.not.exist;
951944

952945
const db = client.db();
@@ -978,18 +971,16 @@ describe('Bulk', function () {
978971
metadata: { requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] } },
979972

980973
test: function (done) {
981-
client.connect(function (err, client) {
974+
client.connect((err, client) => {
982975
const db = client.db();
983976
const col = db.collection('batch_write_ordered_ops_8');
984977

985-
col
986-
.initializeUnorderedBulkOp()
987-
.execute(self.configuration.writeConcernMax(), function (err) {
988-
expect(err).to.be.instanceOf(MongoDriverError);
989-
expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty');
978+
col.initializeUnorderedBulkOp().execute({}, function (err) {
979+
expect(err).to.be.instanceOf(MongoDriverError);
980+
expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty');
990981

991-
client.close(done);
992-
});
982+
client.close(done);
983+
});
993984
});
994985
}
995986
});
@@ -998,7 +989,7 @@ describe('Bulk', function () {
998989
metadata: { requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] } },
999990

1000991
test: function (done) {
1001-
client.connect(function (err, client) {
992+
client.connect((err, client) => {
1002993
const db = client.db();
1003994
const col = db.collection('batch_write_ordered_ops_9');
1004995
const bulk = col.initializeUnorderedBulkOp();
@@ -1025,7 +1016,7 @@ describe('Bulk', function () {
10251016
});
10261017

10271018
it('should provide an accessor for operations on ordered bulk ops', function (done) {
1028-
client.connect(function (err, client) {
1019+
client.connect((err, client) => {
10291020
const db = client.db();
10301021
const col = db.collection('bulk_get_operations_test');
10311022

@@ -1053,7 +1044,7 @@ describe('Bulk', function () {
10531044
metadata: { requires: { topology: 'single', mongodb: '>2.5.4' } },
10541045

10551046
test: function (done) {
1056-
client.connect(function (err, client) {
1047+
client.connect((err, client) => {
10571048
const db = client.db();
10581049
const col = db.collection('batch_write_concerns_ops_1');
10591050
const batch = col.initializeOrderedBulkOp();
@@ -1082,7 +1073,7 @@ describe('Bulk', function () {
10821073
},
10831074

10841075
test: function (done) {
1085-
client.connect(function (err, client) {
1076+
client.connect((err, client) => {
10861077
const db = client.db();
10871078
const docs = [];
10881079
for (let i = 0; i < 5; i++) {
@@ -1106,7 +1097,7 @@ describe('Bulk', function () {
11061097
});
11071098

11081099
it('should provide an accessor for operations on unordered bulk ops', function (done) {
1109-
client.connect(function (err, client) {
1100+
client.connect((err, client) => {
11101101
const db = client.db();
11111102
const col = db.collection('bulk_get_operations_test');
11121103

@@ -1134,7 +1125,7 @@ describe('Bulk', function () {
11341125
metadata: { requires: { topology: 'single', mongodb: '>2.5.4' } },
11351126

11361127
test: function (done) {
1137-
client.connect(function (err, client) {
1128+
client.connect((err, client) => {
11381129
const db = client.db();
11391130
const col = db.collection('batch_write_concerns_ops_1');
11401131
const batch = col.initializeUnorderedBulkOp();
@@ -1156,7 +1147,7 @@ describe('Bulk', function () {
11561147
metadata: { requires: { topology: 'single', mongodb: '>2.5.4' } },
11571148

11581149
test: function (done) {
1159-
client.connect(function (err, client) {
1150+
client.connect((err, client) => {
11601151
const db = client.db();
11611152
const col = db.collection('batch_write_concerns_ops_1');
11621153
let batch = col.initializeOrderedBulkOp();
@@ -1184,7 +1175,7 @@ describe('Bulk', function () {
11841175
metadata: { requires: { topology: 'single', mongodb: '>2.5.4' } },
11851176

11861177
test: function (done) {
1187-
client.connect(function (err, client) {
1178+
client.connect((err, client) => {
11881179
const db = client.db();
11891180
const insertFirst = false;
11901181
const batchSize = 1000;
@@ -1240,7 +1231,7 @@ describe('Bulk', function () {
12401231
metadata: { requires: { topology: 'single', mongodb: '>2.5.4' } },
12411232

12421233
test: function (done) {
1243-
client.connect(function (err, client) {
1234+
client.connect((err, client) => {
12441235
const db = client.db();
12451236
const insertFirst = false;
12461237
const batchSize = 1000;
@@ -1302,7 +1293,7 @@ describe('Bulk', function () {
13021293
},
13031294

13041295
test: function (done) {
1305-
client.connect(function (err, client) {
1296+
client.connect((err, client) => {
13061297
const db = client.db();
13071298
const docs = [];
13081299
for (let i = 0; i < 5; i++) {
@@ -1340,7 +1331,7 @@ describe('Bulk', function () {
13401331
{
13411332
metadata: { requires: { mongodb: '>=2.6.0', topology: 'single' } },
13421333
test: function (done) {
1343-
client.connect(function (err, client) {
1334+
client.connect((err, client) => {
13441335
const db = client.db();
13451336
db.collection('doesnt_matter').insertMany([], { ordered: false }, function (err) {
13461337
expect(err).to.be.instanceOf(MongoDriverError);

test/tools/runner/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ConnectionString from 'mongodb-connection-string-url';
33
import * as qs from 'querystring';
44
import * as url from 'url';
55

6-
import { AuthMechanism } from '../../../src';
6+
import { AuthMechanism, WriteConcernSettings } from '../../../src';
77
import { MongoClient } from '../../../src/mongo_client';
88
import { TopologyType } from '../../../src/sdam/common';
99
import { Topology } from '../../../src/sdam/topology';
@@ -349,7 +349,7 @@ export class TestConfiguration {
349349
return connectionString;
350350
}
351351

352-
writeConcernMax() {
352+
writeConcernMax(): { writeConcern: WriteConcernSettings } {
353353
if (this.topologyType !== TopologyType.Single) {
354354
return { writeConcern: { w: 'majority', wtimeoutMS: 30000 } };
355355
}

0 commit comments

Comments
 (0)