Skip to content

Commit 8f37a9c

Browse files
HanaPearlmannbbeeken
authored andcommitted
changes to pass tests
1 parent 60ea0bc commit 8f37a9c

12 files changed

+106
-75
lines changed

test/functional/apm.test.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -961,13 +961,8 @@ describe('APM', function () {
961961
if (args.requests) params.push(args.requests);
962962

963963
if (args.writeConcern) {
964-
if (options == null) {
965-
options = args.writeConcern;
966-
} else {
967-
for (let name in args.writeConcern) {
968-
options[name] = args.writeConcern[name];
969-
}
970-
}
964+
options = options || {};
965+
options.writeConcern = args.writeConcern;
971966
}
972967

973968
if (typeof args.ordered === 'boolean') {

test/functional/bulk.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Bulk', function () {
7676
metadata: { requires: { mongodb: '>=3.6.x' } },
7777
test: function (done) {
7878
const configuration = this.configuration;
79-
const client = configuration.newClient({}, { w: 1 });
79+
const client = configuration.newClient({ w: 1 });
8080

8181
client.connect((err, client) => {
8282
const db = client.db(configuration.db);
@@ -620,7 +620,7 @@ describe('Bulk', function () {
620620
bulk.find({ b: 1 }).upsert().update({ b: 1 });
621621
bulk.find({ c: 1 }).remove();
622622

623-
bulk.execute({ w: 0 }, function (err, result) {
623+
bulk.execute({ writeConcern: { w: 0 } }, function (err, result) {
624624
expect(err).to.not.exist;
625625
test.equal(0, result.nUpserted);
626626
test.equal(0, result.nInserted);
@@ -1126,7 +1126,7 @@ describe('Bulk', function () {
11261126
bulk.find({ b: 1 }).upsert().update({ b: 1 });
11271127
bulk.find({ c: 1 }).remove();
11281128

1129-
bulk.execute({ w: 0 }, function (err, result) {
1129+
bulk.execute({ writeConcern: { w: 0 } }, function (err, result) {
11301130
expect(err).to.not.exist;
11311131
test.equal(0, result.nUpserted);
11321132
test.equal(0, result.nInserted);
@@ -1162,7 +1162,7 @@ describe('Bulk', function () {
11621162
batch.insert({ a: 1 });
11631163
batch.insert({ a: 2 });
11641164

1165-
batch.execute({ w: 2, wtimeout: 1000 }, function (err) {
1165+
batch.execute({ writeConcern: { w: 2, wtimeout: 1000 } }, function (err) {
11661166
test.ok(err != null);
11671167
test.ok(err.code != null);
11681168
test.ok(err.errmsg != null);
@@ -1233,7 +1233,7 @@ describe('Bulk', function () {
12331233
batch.insert({ a: 1 });
12341234
batch.insert({ a: 2 });
12351235

1236-
batch.execute({ w: 2, wtimeout: 1000 }, function (err) {
1236+
batch.execute({ writeConcern: { w: 2, wtimeout: 1000 } }, function (err) {
12371237
test.ok(err != null);
12381238
test.ok(err.code != null);
12391239
test.ok(err.errmsg != null);

test/functional/collection.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ describe('Collection', function () {
668668
let db;
669669
let collection;
670670
beforeEach(function () {
671-
client = configuration.newClient({}, { w: 1 });
671+
client = configuration.newClient({ w: 1 });
672672

673673
return client.connect().then(client => {
674674
db = client.db(configuration.db);
@@ -852,7 +852,7 @@ describe('Collection', function () {
852852

853853
function testCapped(testConfiguration, config, done) {
854854
const configuration = config.config;
855-
const client = testConfiguration.newClient({}, { w: 1 });
855+
const client = testConfiguration.newClient({ w: 1 });
856856

857857
client.connect((err, client) => {
858858
const db = client.db(configuration.db);
@@ -938,7 +938,7 @@ describe('Collection', function () {
938938
metadata: { requires: { mongodb: '>=3.0.0' } },
939939
test: function (done) {
940940
const configuration = this.configuration;
941-
const client = configuration.newClient({}, { w: 1 });
941+
const client = configuration.newClient({ w: 1 });
942942

943943
let finish = err => {
944944
finish = () => {};

test/functional/command_write_concern.test.js

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ describe('Command Write Concern', function () {
121121

122122
db.collection('test')
123123
.aggregate([{ $match: {} }, { $out: 'readConcernCollectionAggregate1Output' }], {
124-
w: 2,
125-
wtimeout: 1000
124+
writeConcern: {
125+
w: 2,
126+
wtimeout: 1000
127+
}
126128
})
127129
.toArray(function (err) {
128130
expect(err).to.not.exist;
@@ -244,12 +246,16 @@ describe('Command Write Concern', function () {
244246
expect(err).to.not.exist;
245247
var db = client.db(configuration.db);
246248

247-
db.createCollection('test_collection_methods', { w: 2, wtimeout: 1000 }, function (err) {
248-
expect(err).to.not.exist;
249-
test.deepEqual({ w: 2, wtimeout: 1000 }, commandResult.writeConcern);
249+
db.createCollection(
250+
'test_collection_methods',
251+
{ writeConcern: { w: 2, wtimeout: 1000 } },
252+
function (err) {
253+
expect(err).to.not.exist;
254+
test.deepEqual({ w: 2, wtimeout: 1000 }, commandResult.writeConcern);
250255

251-
client.close(done);
252-
});
256+
client.close(done);
257+
}
258+
);
253259
});
254260
});
255261
}
@@ -359,8 +365,7 @@ describe('Command Write Concern', function () {
359365
{ a: 1 },
360366
{
361367
indexOptionDefaults: true,
362-
w: 2,
363-
wtimeout: 1000
368+
writeConcern: { w: 2, wtimeout: 1000 }
364369
},
365370
function (err) {
366371
expect(err).to.not.exist;
@@ -475,8 +480,10 @@ describe('Command Write Concern', function () {
475480

476481
db.collection('indexOptionDefault').drop(
477482
{
478-
w: 2,
479-
wtimeout: 1000
483+
writeConcern: {
484+
w: 2,
485+
wtimeout: 1000
486+
}
480487
},
481488
function (err) {
482489
expect(err).to.not.exist;
@@ -591,8 +598,10 @@ describe('Command Write Concern', function () {
591598

592599
db.dropDatabase(
593600
{
594-
w: 2,
595-
wtimeout: 1000
601+
writeConcern: {
602+
w: 2,
603+
wtimeout: 1000
604+
}
596605
},
597606
function (err) {
598607
expect(err).to.not.exist;
@@ -707,8 +716,10 @@ describe('Command Write Concern', function () {
707716

708717
db.collection('test').dropIndexes(
709718
{
710-
w: 2,
711-
wtimeout: 1000
719+
writeConcern: {
720+
w: 2,
721+
wtimeout: 1000
722+
}
712723
},
713724
function (err) {
714725
expect(err).to.not.exist;
@@ -831,8 +842,7 @@ describe('Command Write Concern', function () {
831842
reduce,
832843
{
833844
out: { replace: 'tempCollection' },
834-
w: 2,
835-
wtimeout: 1000
845+
writeConcern: { w: 2, wtimeout: 1000 }
836846
},
837847
function (err) {
838848
expect(err).to.not.exist;
@@ -945,12 +955,17 @@ describe('Command Write Concern', function () {
945955
expect(err).to.not.exist;
946956
var db = client.db(configuration.db);
947957

948-
db.admin().addUser('kay:kay', 'abc123', { w: 2, wtimeout: 1000 }, function (err) {
949-
expect(err).to.not.exist;
950-
test.deepEqual({ w: 2, wtimeout: 1000 }, commandResult.writeConcern);
958+
db.admin().addUser(
959+
'kay:kay',
960+
'abc123',
961+
{ writeConcern: { w: 2, wtimeout: 1000 } },
962+
function (err) {
963+
expect(err).to.not.exist;
964+
test.deepEqual({ w: 2, wtimeout: 1000 }, commandResult.writeConcern);
951965

952-
client.close(done);
953-
});
966+
client.close(done);
967+
}
968+
);
954969
});
955970
});
956971
}
@@ -1055,7 +1070,9 @@ describe('Command Write Concern', function () {
10551070
expect(err).to.not.exist;
10561071
var db = client.db(configuration.db);
10571072

1058-
db.admin().removeUser('kay:kay', { w: 2, wtimeout: 1000 }, function (err) {
1073+
db.admin().removeUser('kay:kay', { writeConcern: { w: 2, wtimeout: 1000 } }, function (
1074+
err
1075+
) {
10591076
expect(err).to.not.exist;
10601077
test.deepEqual({ w: 2, wtimeout: 1000 }, commandResult.writeConcern);
10611078

@@ -1170,7 +1187,7 @@ describe('Command Write Concern', function () {
11701187
{ a: 1 },
11711188
[['a', 1]],
11721189
{ $set: { b1: 1 } },
1173-
{ new: true, w: 2, wtimeout: 1000 },
1190+
{ new: true, writeConcern: { w: 2, wtimeout: 1000 } },
11741191
function (err) {
11751192
expect(err).to.not.exist;
11761193
test.deepEqual({ w: 2, wtimeout: 1000 }, commandResult.writeConcern);

test/functional/find_and_modify.test.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,11 @@ describe('Find and Modify', function () {
4040

4141
var collection = db.collection('findAndModifyTEST');
4242
// Execute findOneAndUpdate
43-
collection.findOneAndUpdate({}, { $set: { a: 1 } }, { fsync: 1 }, function (err) {
44-
expect(err).to.not.exist;
45-
test.deepEqual({ fsync: 1 }, started[0].command.writeConcern);
46-
47-
// Cleanup
48-
started = [];
49-
succeeded = [];
50-
51-
// Execute findOneAndReplace
52-
collection.findOneAndReplace({}, { b: 1 }, { fsync: 1 }, function (err) {
43+
collection.findOneAndUpdate(
44+
{},
45+
{ $set: { a: 1 } },
46+
{ writeConcern: { fsync: 1 } },
47+
function (err) {
5348
expect(err).to.not.exist;
5449
test.deepEqual({ fsync: 1 }, started[0].command.writeConcern);
5550

@@ -58,15 +53,27 @@ describe('Find and Modify', function () {
5853
succeeded = [];
5954

6055
// Execute findOneAndReplace
61-
collection.findOneAndDelete({}, { fsync: 1 }, function (err) {
56+
collection.findOneAndReplace({}, { b: 1 }, { writeConcern: { fsync: 1 } }, function (
57+
err
58+
) {
6259
expect(err).to.not.exist;
6360
test.deepEqual({ fsync: 1 }, started[0].command.writeConcern);
6461

65-
listener.uninstrument();
66-
client.close(done);
62+
// Cleanup
63+
started = [];
64+
succeeded = [];
65+
66+
// Execute findOneAndReplace
67+
collection.findOneAndDelete({}, { writeConcern: { fsync: 1 } }, function (err) {
68+
expect(err).to.not.exist;
69+
test.deepEqual({ fsync: 1 }, started[0].command.writeConcern);
70+
71+
listener.uninstrument();
72+
client.close(done);
73+
});
6774
});
68-
});
69-
});
75+
}
76+
);
7077
});
7178
}
7279
});
@@ -100,7 +107,7 @@ describe('Find and Modify', function () {
100107
var db = client.db(configuration.db);
101108
expect(err).to.not.exist;
102109

103-
var collection = db.collection('findAndModifyTEST', { fsync: 1 });
110+
var collection = db.collection('findAndModifyTEST', { writeConcern: { fsync: 1 } });
104111
// Execute findOneAndUpdate
105112
collection.findOneAndUpdate({}, { $set: { a: 1 } }, function (err) {
106113
expect(err).to.not.exist;

test/functional/insert.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ describe('Insert', function () {
14511451
client.connect(function (err, client) {
14521452
var db = client.db(configuration.db);
14531453
var collection = db.collection('gh-completely3');
1454-
collection.update({ a: 1 }, { a: 2 }, { upsert: true, w: 0 }, cb);
1454+
collection.update({ a: 1 }, { a: 2 }, { upsert: true, writeConcern: { w: 0 } }, cb);
14551455
});
14561456
}
14571457
});

test/functional/mongo_client.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ describe('MongoClient', function () {
2525
const client = configuration.newClient(
2626
{},
2727
{
28-
w: 1,
29-
wtimeout: 1000,
30-
fsync: true,
31-
j: true,
28+
writeConcern: { w: 1, wtimeout: 1000, fsync: true, j: true },
3229
readPreference: 'nearest',
3330
readPreferenceTags: { loc: 'ny' },
3431
forceServerObjectId: true,

test/functional/operation_promises_example.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,12 +2020,12 @@ describe('Operation (Promises)', function () {
20202020

20212021
// Insert a bunch of documents
20222022
return collection
2023-
.insertMany([{ a: 1 }, { b: 2 }], { w: 1 })
2023+
.insertMany([{ a: 1 }, { b: 2 }], { writeConcern: { w: 1 } })
20242024
.then(function (result) {
20252025
test.ok(result);
20262026

20272027
// Remove all the document
2028-
return collection.removeOne({ a: 1 }, { w: 1 });
2028+
return collection.removeOne({ a: 1 }, { writeConcern: { w: 1 } });
20292029
})
20302030
.then(function (r) {
20312031
expect(r).property('deletedCount').to.equal(1);

test/functional/promises_collection.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ describe('Promises (Collection)', function () {
296296
const client = configuration.newClient(url);
297297
client.connect().then(function (client) {
298298
var db = client.db(configuration.db);
299-
var bulk = db.collection('unordered_bulk_promise_form').initializeUnorderedBulkOp({ w: 1 });
299+
var bulk = db
300+
.collection('unordered_bulk_promise_form')
301+
.initializeUnorderedBulkOp({ writeConcern: { w: 1 } });
300302
bulk.insert({ a: 1 });
301303
return bulk
302304
.execute()
@@ -329,7 +331,9 @@ describe('Promises (Collection)', function () {
329331
const client = configuration.newClient(url);
330332
client.connect().then(function (client) {
331333
var db = client.db(configuration.db);
332-
var bulk = db.collection('unordered_bulk_promise_form').initializeOrderedBulkOp({ w: 1 });
334+
var bulk = db
335+
.collection('unordered_bulk_promise_form')
336+
.initializeOrderedBulkOp({ writeConcern: { w: 1 } });
333337
bulk.insert({ a: 1 });
334338
return bulk
335339
.execute()

test/functional/spec-runner/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,29 +184,31 @@ function prepareDatabaseForSuite(suite, context) {
184184

185185
const coll = db.collection(context.collectionName);
186186
return setupPromise
187-
.then(() => coll.drop({ writeConcern: 'majority' }))
187+
.then(() => coll.drop({ writeConcern: { w: 'majority' } }))
188188
.catch(err => {
189189
if (!err.message.match(/ns not found/)) throw err;
190190
})
191191
.then(() => {
192192
if (suite.key_vault_data) {
193193
const dataKeysCollection = context.sharedClient.db('keyvault').collection('datakeys');
194194
return dataKeysCollection
195-
.drop({ w: 'majority' })
195+
.drop({ writeConcern: { w: 'majority' } })
196196
.catch(err => {
197197
if (!err.message.match(/ns not found/)) {
198198
throw err;
199199
}
200200
})
201201
.then(() => {
202202
if (suite.key_vault_data.length) {
203-
return dataKeysCollection.insertMany(suite.key_vault_data, { w: 'majority' });
203+
return dataKeysCollection.insertMany(suite.key_vault_data, {
204+
writeConcern: { w: 'majority' }
205+
});
204206
}
205207
});
206208
}
207209
})
208210
.then(() => {
209-
const options = { w: 'majority' };
211+
const options = { writeConcern: { w: 'majority' } };
210212
if (suite.json_schema) {
211213
options.validator = { $jsonSchema: suite.json_schema };
212214
}
@@ -215,7 +217,7 @@ function prepareDatabaseForSuite(suite, context) {
215217
})
216218
.then(() => {
217219
if (suite.data && Array.isArray(suite.data) && suite.data.length > 0) {
218-
return coll.insertMany(suite.data, { w: 'majority' });
220+
return coll.insertMany(suite.data, { writeConcern: { w: 'majority' } });
219221
}
220222
})
221223
.then(() => {

0 commit comments

Comments
 (0)