Skip to content

Commit 5d1c6fa

Browse files
committed
update some tests to use new wc option
1 parent f92ed0b commit 5d1c6fa

File tree

11 files changed

+148
-106
lines changed

11 files changed

+148
-106
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

@@ -431,7 +431,7 @@ describe('Aggregation', function () {
431431
// Create a collection
432432
var collection = db.collection('shouldCorrectlyDoAggWithCursorGet');
433433
// Insert the docs
434-
collection.insert(docs, { w: 1 }, function (err, result) {
434+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
435435
expect(result).to.exist;
436436
expect(err).to.not.exist;
437437

@@ -520,7 +520,7 @@ describe('Aggregation', function () {
520520
// Create a collection
521521
const collection = db.collection('shouldCorrectlyDoAggWithCursorGet');
522522
// Insert the docs
523-
collection.insert(docs, { w: 1 }, (err, result) => {
523+
collection.insert(docs, { writeConcern: { w: 1 } }, (err, result) => {
524524
expect(result).to.exist;
525525
expect(err).to.not.exist;
526526

@@ -609,7 +609,7 @@ describe('Aggregation', function () {
609609
// Create a collection
610610
var collection = db.collection('shouldCorrectlyDoAggWithCursorGet');
611611
// Insert the docs
612-
collection.insert(docs, { w: 1 }, function (err, result) {
612+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
613613
expect(result).to.exist;
614614
expect(err).to.not.exist;
615615

@@ -694,7 +694,7 @@ describe('Aggregation', function () {
694694
// Create a collection
695695
var collection = db.collection('shouldCorrectlyDoAggWithCursorGet');
696696
// Insert the docs
697-
collection.insert(docs, { w: 1 }, function (err, result) {
697+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
698698
expect(result).to.exist;
699699
expect(err).to.not.exist;
700700

@@ -890,7 +890,7 @@ describe('Aggregation', function () {
890890
// Create a collection
891891
var collection = db.collection('shouldCorrectlyDoAggWithCursorGetStream');
892892
// Insert the docs
893-
collection.insert(docs, { w: 1 }, function (err, result) {
893+
collection.insert(docs, { writeConcern: { w: 1 } }, function (err, result) {
894894
expect(result).to.exist;
895895
expect(err).to.not.exist;
896896

@@ -1033,7 +1033,7 @@ describe('Aggregation', function () {
10331033
// Create a collection
10341034
const collection = db.collection('shouldCorrectlyDoAggWithCursorMaxTimeMSSet');
10351035
// Insert the docs
1036-
collection.insert(docs, { w: 1 }, (err, result) => {
1036+
collection.insert(docs, { writeConcern: { w: 1 } }, (err, result) => {
10371037
expect(result).to.exist;
10381038
expect(err).to.not.exist;
10391039

@@ -1203,7 +1203,7 @@ describe('Aggregation', function () {
12031203
// Create a collection
12041204
var collection = db.collection('shouldCorrectlyQueryUsingISODate');
12051205
// Insert the docs
1206-
collection.insertMany(docs, { w: 1 }, function (err, result) {
1206+
collection.insertMany(docs, { writeConcern: { w: 1 } }, function (err, result) {
12071207
expect(result).to.exist;
12081208
expect(err).to.not.exist;
12091209

@@ -1255,7 +1255,10 @@ describe('Aggregation', function () {
12551255
// Create a collection
12561256
var collection = db.collection('shouldCorrectlyQueryUsingISODate3');
12571257
// Insert the docs
1258-
collection.insertMany([{ a: 1 }, { b: 1 }], { w: 1 }, function (err, result) {
1258+
collection.insertMany([{ a: 1 }, { b: 1 }], { writeConcern: { w: 1 } }, function (
1259+
err,
1260+
result
1261+
) {
12591262
expect(result).to.exist;
12601263
expect(err).to.not.exist;
12611264

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
@@ -202,7 +202,7 @@ describe('Causal Consistency', function () {
202202

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

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
}
@@ -2582,7 +2586,7 @@ describe('Change Streams', function () {
25822586
coll = client.db('integration_tests').collection('setupAfterTest');
25832587
const changeStream = coll.watch();
25842588
waitForStarted(changeStream, () => {
2585-
coll.insertOne({ x: 1 }, { w: 'majority', j: true }, err => {
2589+
coll.insertOne({ x: 1 }, { writeConcern: { w: 'majority', j: true } }, err => {
25862590
expect(err).to.not.exist;
25872591

25882592
coll.drop(err => {
@@ -2610,7 +2614,7 @@ describe('Change Streams', function () {
26102614
const changeStream = coll.watch([], { startAfter });
26112615
this.defer(() => changeStream.close());
26122616

2613-
coll.insertOne({ x: 2 }, { w: 'majority', j: true }, err => {
2617+
coll.insertOne({ x: 2 }, { writeConcern: { w: 'majority', j: true } }, err => {
26142618
expect(err).to.not.exist;
26152619
changeStream.once('change', change => {
26162620
expect(change).to.containSubset({
@@ -2630,7 +2634,7 @@ describe('Change Streams', function () {
26302634
const changeStream = coll.watch([], { startAfter });
26312635
this.defer(() => changeStream.close());
26322636

2633-
coll.insertOne({ x: 2 }, { w: 'majority', j: true }, err => {
2637+
coll.insertOne({ x: 2 }, { writeConcern: { w: 'majority', j: true } }, err => {
26342638
expect(err).to.not.exist;
26352639
exhaust(changeStream, (err, bag) => {
26362640
expect(err).to.not.exist;
@@ -2675,7 +2679,7 @@ describe('Change Streams', function () {
26752679
waitForStarted(changeStream, () => {
26762680
triggerResumableError(changeStream, () => {
26772681
events.push('error');
2678-
coll.insertOne({ x: 2 }, { w: 'majority', j: true });
2682+
coll.insertOne({ x: 2 }, { writeConcern: { w: 'majority', j: true } });
26792683
});
26802684
});
26812685
}
@@ -2715,8 +2719,8 @@ describe('Change Streams', function () {
27152719
waitForStarted(changeStream, () =>
27162720
this.defer(
27172721
coll
2718-
.insertOne({ x: 2 }, { w: 'majority', j: true })
2719-
.then(() => coll.insertOne({ x: 3 }, { w: 'majority', j: true }))
2722+
.insertOne({ x: 2 }, { writeConcern: { w: 'majority', j: true } })
2723+
.then(() => coll.insertOne({ x: 3 }, { writeConcern: { w: 'majority', j: true } }))
27202724
)
27212725
);
27222726
}

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
var db = client.db(configuration.db);
4343
expect(err).to.not.exist;
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
var db = client.db(configuration.db);
107111
expect(err).to.not.exist;
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)