Skip to content

Commit 5f04cfc

Browse files
HanaPearlmannbbeeken
authored andcommitted
update some tests to use new wc option
1 parent 8f37a9c commit 5f04cfc

File tree

10 files changed

+112
-74
lines changed

10 files changed

+112
-74
lines changed

src/operations/map_reduce.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ const exclusionList = [
2323
'readConcern',
2424
'session',
2525
'bypassDocumentValidation',
26-
'w',
27-
'wtimeout',
28-
'j',
2926
'writeConcern',
3027
'raw',
3128
'fieldsAsRaw',

test/examples/transactions.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,15 @@ describe('examples(transactions):', function () {
234234

235235
// Prereq: Create collections.
236236

237-
await client.db('mydb1').collection('foo').insertOne({ abc: 0 }, { w: 'majority' });
238-
239-
await client.db('mydb2').collection('bar').insertOne({ xyz: 0 }, { w: 'majority' });
237+
await client
238+
.db('mydb1')
239+
.collection('foo')
240+
.insertOne({ abc: 0 }, { writeConcern: { w: 'majority' } });
241+
242+
await client
243+
.db('mydb2')
244+
.collection('bar')
245+
.insertOne({ xyz: 0 }, { writeConcern: { w: 'majority' } });
240246

241247
// Step 1: Start a Client Session
242248
const session = client.startSession();

test/functional/aggregation.test.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('Aggregation', function () {
5353
// Create a collection
5454
var collection = db.collection('shouldCorrectlyExecuteSimpleAggregationPipelineUsingArray');
5555
// Insert the docs
56-
collection.insert(docs, { w: 1 }, function (err, result) {
56+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
5757
expect(result).to.exist;
5858
expect(err).to.not.exist;
5959

@@ -172,7 +172,7 @@ describe('Aggregation', function () {
172172
'shouldCorrectlyExecuteSimpleAggregationPipelineUsingArguments'
173173
);
174174
// Insert the docs
175-
collection.insert(docs, { w: 1 }, function (err, result) {
175+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
176176
expect(result).to.exist;
177177
expect(err).to.not.exist;
178178

@@ -260,7 +260,7 @@ describe('Aggregation', function () {
260260
'shouldCorrectlyExecuteSimpleAggregationPipelineUsingArguments'
261261
);
262262
// Insert the docs
263-
collection.insert(docs, { w: 1 }, function (err, result) {
263+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
264264
expect(result).to.exist;
265265
expect(err).to.not.exist;
266266

@@ -346,7 +346,7 @@ describe('Aggregation', function () {
346346
// Create a collection
347347
var collection = db.collection('shouldCorrectlyDoAggWithCursorGet');
348348
// Insert the docs
349-
collection.insert(docs, { w: 1 }, function (err, result) {
349+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
350350
expect(err).to.not.exist;
351351
expect(result).to.exist;
352352

@@ -426,7 +426,7 @@ describe('Aggregation', function () {
426426
// Create a collection
427427
var collection = db.collection('shouldCorrectlyDoAggWithCursorGet');
428428
// Insert the docs
429-
collection.insert(docs, { w: 1 }, function (err, result) {
429+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
430430
expect(result).to.exist;
431431
expect(err).to.not.exist;
432432

@@ -515,7 +515,7 @@ describe('Aggregation', function () {
515515
// Create a collection
516516
const collection = db.collection('shouldCorrectlyDoAggWithCursorGet');
517517
// Insert the docs
518-
collection.insert(docs, { w: 1 }, (err, result) => {
518+
collection.insert(docs, { writeConcern: { w: 1 } }, (err, result) => {
519519
expect(result).to.exist;
520520
expect(err).to.not.exist;
521521

@@ -604,7 +604,7 @@ describe('Aggregation', function () {
604604
// Create a collection
605605
var collection = db.collection('shouldCorrectlyDoAggWithCursorGet');
606606
// Insert the docs
607-
collection.insert(docs, { w: 1 }, function (err, result) {
607+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
608608
expect(result).to.exist;
609609
expect(err).to.not.exist;
610610

@@ -689,7 +689,7 @@ describe('Aggregation', function () {
689689
// Create a collection
690690
var collection = db.collection('shouldCorrectlyDoAggWithCursorGet');
691691
// Insert the docs
692-
collection.insert(docs, { w: 1 }, function (err, result) {
692+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
693693
expect(result).to.exist;
694694
expect(err).to.not.exist;
695695

@@ -885,7 +885,7 @@ describe('Aggregation', function () {
885885
// Create a collection
886886
var collection = db.collection('shouldCorrectlyDoAggWithCursorGetStream');
887887
// Insert the docs
888-
collection.insert(docs, { w: 1 }, function (err, result) {
888+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
889889
expect(result).to.exist;
890890
expect(err).to.not.exist;
891891

@@ -1027,7 +1027,7 @@ describe('Aggregation', function () {
10271027
// Create a collection
10281028
const collection = db.collection('shouldCorrectlyDoAggWithCursorMaxTimeMSSet');
10291029
// Insert the docs
1030-
collection.insert(docs, { w: 1 }, (err, result) => {
1030+
collection.insert(docs, { writeConcern: { w: 1 } }, (err, result) => {
10311031
expect(result).to.exist;
10321032
expect(err).to.not.exist;
10331033

@@ -1197,7 +1197,7 @@ describe('Aggregation', function () {
11971197
// Create a collection
11981198
var collection = db.collection('shouldCorrectlyQueryUsingISODate');
11991199
// Insert the docs
1200-
collection.insertMany(docs, { w: 1 }, function (err, result) {
1200+
collection.insertMany(docs, { writeConcern: { w: 1 } }, function (err, result) {
12011201
expect(result).to.exist;
12021202
expect(err).to.not.exist;
12031203

@@ -1249,7 +1249,10 @@ describe('Aggregation', function () {
12491249
// Create a collection
12501250
var collection = db.collection('shouldCorrectlyQueryUsingISODate3');
12511251
// Insert the docs
1252-
collection.insertMany([{ a: 1 }, { b: 1 }], { w: 1 }, function (err, result) {
1252+
collection.insertMany([{ a: 1 }, { b: 1 }], { writeConcern: { w: 1 } }, function (
1253+
err,
1254+
result
1255+
) {
12531256
expect(result).to.exist;
12541257
expect(err).to.not.exist;
12551258

test/functional/apm.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ describe('APM', function () {
358358
// Insert test documents
359359
return db
360360
.collection('apm_test_2')
361-
.insertMany([{ a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }], { w: 1 });
361+
.insertMany([{ a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }], {
362+
writeConcern: { w: 1 }
363+
});
362364
})
363365
.then(r => {
364366
expect(r.insertedCount).to.equal(6);
@@ -529,7 +531,9 @@ describe('APM', function () {
529531
.then(() =>
530532
db
531533
.collection('apm_test_2')
532-
.insertMany([{ a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }], { w: 1 })
534+
.insertMany([{ a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }], {
535+
writeConcern: { w: 1 }
536+
})
533537
)
534538
.then(r => {
535539
expect(r.insertedCount).to.equal(6);

test/functional/causal_consistency.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ describe('Causal Consistency', function () {
203203

204204
return db
205205
.collection('causal_test')
206-
.insert({}, { session: session, w: 0 })
206+
.insert({}, { session: session, writeConcern: { w: 0 } })
207207
.then(() => {
208208
expect(session.operationTime).to.be.null;
209209
});

test/functional/change_stream.test.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ function withChangeStream(dbName, collectionName, callback) {
3131
return withClient((client, done) => {
3232
const db = client.db(dbName);
3333
db.dropCollection(collectionName, () => {
34-
db.createCollection(collectionName, { w: 'majority' }, (err, collection) => {
35-
if (err) return done(err);
36-
withCursor(
37-
collection.watch(),
38-
(cursor, done) => callback(collection, cursor, done),
39-
err => collection.drop(dropErr => done(err || dropErr))
40-
);
41-
});
34+
db.createCollection(
35+
collectionName,
36+
{ writeConcern: { w: 'majority' } },
37+
(err, collection) => {
38+
if (err) return done(err);
39+
withCursor(
40+
collection.watch(),
41+
(cursor, done) => callback(collection, cursor, done),
42+
err => collection.drop(dropErr => done(err || dropErr))
43+
);
44+
}
45+
);
4246
});
4347
});
4448
}
@@ -2537,7 +2541,7 @@ describe('Change Streams', function () {
25372541
coll = client.db('integration_tests').collection('setupAfterTest');
25382542
const changeStream = coll.watch();
25392543
waitForStarted(changeStream, () => {
2540-
coll.insertOne({ x: 1 }, { w: 'majority', j: true }, err => {
2544+
coll.insertOne({ x: 1 }, { writeConcern: { w: 'majority', j: true } }, err => {
25412545
expect(err).to.not.exist;
25422546

25432547
coll.drop(err => {
@@ -2565,7 +2569,7 @@ describe('Change Streams', function () {
25652569
const changeStream = coll.watch([], { startAfter });
25662570
this.defer(() => changeStream.close());
25672571

2568-
coll.insertOne({ x: 2 }, { w: 'majority', j: true }, err => {
2572+
coll.insertOne({ x: 2 }, { writeConcern: { w: 'majority', j: true } }, err => {
25692573
expect(err).to.not.exist;
25702574
changeStream.once('change', change => {
25712575
expect(change).to.containSubset({
@@ -2585,7 +2589,7 @@ describe('Change Streams', function () {
25852589
const changeStream = coll.watch([], { startAfter });
25862590
this.defer(() => changeStream.close());
25872591

2588-
coll.insertOne({ x: 2 }, { w: 'majority', j: true }, err => {
2592+
coll.insertOne({ x: 2 }, { writeConcern: { w: 'majority', j: true } }, err => {
25892593
expect(err).to.not.exist;
25902594
exhaust(changeStream, (err, bag) => {
25912595
expect(err).to.not.exist;
@@ -2630,7 +2634,7 @@ describe('Change Streams', function () {
26302634
waitForStarted(changeStream, () => {
26312635
triggerResumableError(changeStream, () => {
26322636
events.push('error');
2633-
coll.insertOne({ x: 2 }, { w: 'majority', j: true });
2637+
coll.insertOne({ x: 2 }, { writeConcern: { w: 'majority', j: true } });
26342638
});
26352639
});
26362640
}
@@ -2670,8 +2674,8 @@ describe('Change Streams', function () {
26702674
waitForStarted(changeStream, () =>
26712675
this.defer(
26722676
coll
2673-
.insertOne({ x: 2 }, { w: 'majority', j: true })
2674-
.then(() => coll.insertOne({ x: 3 }, { w: 'majority', j: true }))
2677+
.insertOne({ x: 2 }, { writeConcern: { w: 'majority', j: true } })
2678+
.then(() => coll.insertOne({ x: 3 }, { writeConcern: { w: 'majority', j: true } }))
26752679
)
26762680
);
26772681
}

test/functional/change_stream_spec.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ describe('Change Stream Spec', function () {
3737
const sDB = suite.database_name;
3838
const sColl = suite.collection_name;
3939
const configuration = this.configuration;
40-
return Promise.all(ALL_DBS.map(db => gc.db(db).dropDatabase({ w: 'majority' })))
40+
return Promise.all(
41+
ALL_DBS.map(db => gc.db(db).dropDatabase({ writeConcern: { w: 'majority' } }))
42+
)
4143
.then(() => gc.db(sDB).createCollection(sColl))
4244
.then(() => {
4345
if (suite.database2_name && suite.collection2_name) {

test/functional/collection.test.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -493,23 +493,28 @@ describe('Collection', function () {
493493
expect(err).to.not.exist;
494494

495495
// Index name happens to be the same as collection name
496-
db.createIndex(testCollection, 'collection_124', { w: 1 }, (err, indexName) => {
497-
expect(err).to.not.exist;
498-
expect(indexName).to.equal('collection_124_1');
499-
500-
db.listCollections().toArray((err, documents) => {
496+
db.createIndex(
497+
testCollection,
498+
'collection_124',
499+
{ writeConcern: { w: 1 } },
500+
(err, indexName) => {
501501
expect(err).to.not.exist;
502-
expect(documents.length > 1).to.be.true;
503-
let found = false;
502+
expect(indexName).to.equal('collection_124_1');
504503

505-
documents.forEach(document => {
506-
if (document.name === testCollection) found = true;
507-
});
504+
db.listCollections().toArray((err, documents) => {
505+
expect(err).to.not.exist;
506+
expect(documents.length > 1).to.be.true;
507+
let found = false;
508508

509-
expect(found).to.be.true;
510-
done();
511-
});
512-
});
509+
documents.forEach(document => {
510+
if (document.name === testCollection) found = true;
511+
});
512+
513+
expect(found).to.be.true;
514+
done();
515+
});
516+
}
517+
);
513518
});
514519
});
515520

@@ -630,15 +635,15 @@ describe('Collection', function () {
630635
) {
631636
collection.createIndex(
632637
{ createdAt: 1 },
633-
{ expireAfterSeconds: 1, w: 1 },
638+
{ expireAfterSeconds: 1, writeConcern: { w: 1 } },
634639
errorCallBack
635640
);
636641
} else if (
637642
test.title === 'should correctly create TTL collection with index using ensureIndex'
638643
) {
639644
collection.ensureIndex(
640645
{ createdAt: 1 },
641-
{ expireAfterSeconds: 1, w: 1 },
646+
{ expireAfterSeconds: 1, writeConcern: { w: 1 } },
642647
errorCallBack
643648
);
644649
}

test/functional/connection.test.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,22 @@ describe('Connection', function () {
4242
expect(err).to.not.exist;
4343
var db = client.db(configuration.db);
4444

45-
db.collection('domainSocketCollection0').insert({ a: 1 }, { w: 1 }, function (err) {
46-
expect(err).to.not.exist;
45+
db.collection('domainSocketCollection0').insert(
46+
{ a: 1 },
47+
{ writeConcern: { w: 1 } },
48+
function (err) {
49+
expect(err).to.not.exist;
4750

48-
db.collection('domainSocketCollection0')
49-
.find({ a: 1 })
50-
.toArray(function (err, items) {
51-
expect(err).to.not.exist;
52-
test.equal(1, items.length);
51+
db.collection('domainSocketCollection0')
52+
.find({ a: 1 })
53+
.toArray(function (err, items) {
54+
expect(err).to.not.exist;
55+
test.equal(1, items.length);
5356

54-
client.close(done);
55-
});
56-
});
57+
client.close(done);
58+
});
59+
}
60+
);
5761
});
5862
}
5963
});
@@ -106,18 +110,22 @@ describe('Connection', function () {
106110
expect(err).to.not.exist;
107111
var db = client.db(configuration.db);
108112

109-
db.collection('domainSocketCollection1').insert({ x: 1 }, { w: 1 }, function (err) {
110-
expect(err).to.not.exist;
113+
db.collection('domainSocketCollection1').insert(
114+
{ x: 1 },
115+
{ writeConcern: { w: 1 } },
116+
function (err) {
117+
expect(err).to.not.exist;
111118

112-
db.collection('domainSocketCollection1')
113-
.find({ x: 1 })
114-
.toArray(function (err, items) {
115-
expect(err).to.not.exist;
116-
test.equal(1, items.length);
119+
db.collection('domainSocketCollection1')
120+
.find({ x: 1 })
121+
.toArray(function (err, items) {
122+
expect(err).to.not.exist;
123+
test.equal(1, items.length);
117124

118-
client.close(done);
119-
});
120-
});
125+
client.close(done);
126+
});
127+
}
128+
);
121129
});
122130
}
123131
});
@@ -135,7 +143,7 @@ describe('Connection', function () {
135143
db.collection(testName, function (err, collection) {
136144
expect(err).to.not.exist;
137145

138-
collection.insert({ foo: 123 }, { w: 1 }, function (err) {
146+
collection.insert({ foo: 123 }, { writeConcern: { w: 1 } }, function (err) {
139147
expect(err).to.not.exist;
140148

141149
db.dropDatabase(function (err, dropped) {

0 commit comments

Comments
 (0)