Skip to content

Commit 0312076

Browse files
committed
NODE-485 test showing driver works as intended (updateOne crash when a new document is inserted for {upsert: true, w: 0})
1 parent 47dbb49 commit 0312076

File tree

2 files changed

+378
-355
lines changed

2 files changed

+378
-355
lines changed

test/functional/crud_api_tests.js

Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports['should correctly execute find method using crud api'] = {
1414
// Add a tag that our runner can trigger on
1515
// in this case we are setting that node needs to be higher than 0.10.X to run
1616
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
17-
17+
1818
// The actual test we wish to run
1919
test: function(configuration, test) {
2020
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
@@ -40,7 +40,7 @@ exports['should correctly execute find method using crud api'] = {
4040
.skip(0)
4141
.sort({a:1});
4242

43-
//
43+
//
4444
// Exercise count method
4545
// -------------------------------------------------
4646
var countMethod = function() {
@@ -52,12 +52,12 @@ exports['should correctly execute find method using crud api'] = {
5252
});
5353
}
5454

55-
//
55+
//
5656
// Exercise legacy method each
5757
// -------------------------------------------------
5858
var eachMethod = function() {
5959
var count = 0;
60-
60+
6161
cursor.each(function(err, doc) {
6262
test.equal(null, err);
6363
if(doc) count = count + 1;
@@ -98,7 +98,7 @@ exports['should correctly execute find method using crud api'] = {
9898
nextObjectMethod();
9999
});
100100
});
101-
});
101+
});
102102
}
103103

104104
//
@@ -120,7 +120,7 @@ exports['should correctly execute find method using crud api'] = {
120120
streamMethod();
121121
});
122122
});
123-
});
123+
});
124124
}
125125

126126
//
@@ -134,7 +134,7 @@ exports['should correctly execute find method using crud api'] = {
134134
});
135135

136136
clonedCursor.once('end', function() {
137-
test.equal(2, count);
137+
test.equal(2, count);
138138
explainMethod();
139139
});
140140
}
@@ -149,7 +149,7 @@ exports['should correctly execute find method using crud api'] = {
149149
test.ok(result != null);
150150

151151
db.close();
152-
test.done();
152+
test.done();
153153
});
154154
}
155155

@@ -167,7 +167,7 @@ exports['should correctly execute aggregation method using crud api'] = {
167167
// Add a tag that our runner can trigger on
168168
// in this case we are setting that node needs to be higher than 0.10.X to run
169169
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
170-
170+
171171
// The actual test we wish to run
172172
test: function(configuration, test) {
173173
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
@@ -218,7 +218,7 @@ exports['should correctly execute aggregation method using crud api'] = {
218218
test.equal(null, err);
219219
test.equal(3, docs.length);
220220
testNext();
221-
});
221+
});
222222
}
223223

224224
//
@@ -247,7 +247,7 @@ exports['should correctly execute aggregation method using crud api'] = {
247247
test.equal(3, count);
248248
testStream();
249249
}
250-
});
250+
});
251251
}
252252

253253
//
@@ -262,9 +262,9 @@ exports['should correctly execute aggregation method using crud api'] = {
262262
});
263263

264264
cursor.once('end', function() {
265-
test.equal(3, count);
265+
test.equal(3, count);
266266
testExplain();
267-
});
267+
});
268268
}
269269

270270
//
@@ -278,7 +278,7 @@ exports['should correctly execute aggregation method using crud api'] = {
278278

279279
db.close();
280280
test.done();
281-
});
281+
});
282282
}
283283

284284
testAllMethods();
@@ -291,7 +291,7 @@ exports['should correctly execute insert methods using crud api'] = {
291291
// Add a tag that our runner can trigger on
292292
// in this case we are setting that node needs to be higher than 0.10.X to run
293293
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
294-
294+
295295
// The actual test we wish to run
296296
test: function(configuration, test) {
297297
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
@@ -316,7 +316,7 @@ exports['should correctly execute insert methods using crud api'] = {
316316
var bulkAPIInsert = function() {
317317
var bulk = db.collection('t2_2').initializeOrderedBulkOp();
318318
bulk.insert({a:1});
319-
bulk.insert({a:1});
319+
bulk.insert({a:1});
320320
bulk.execute(function(err, r) {
321321
test.equal(null, err);
322322

@@ -333,7 +333,7 @@ exports['should correctly execute insert methods using crud api'] = {
333333
test.equal(1, r.result.n);
334334
test.equal(1, r.insertedCount);
335335
test.ok(r.insertedId != null);
336-
336+
337337
insertMany();
338338
});
339339
}
@@ -348,7 +348,7 @@ exports['should correctly execute insert methods using crud api'] = {
348348
test.equal(2, r.result.n);
349349
test.equal(2, r.insertedCount);
350350
test.equal(2, r.insertedIds.length);
351-
351+
352352
// Ordered bulk unordered
353353
bulkWriteUnOrdered();
354354
});
@@ -361,7 +361,7 @@ exports['should correctly execute insert methods using crud api'] = {
361361
db.collection('t2_5').insertMany([{c:1}], {w:1}, function(err, r) {
362362
test.equal(null, err);
363363
test.equal(1, r.result.n);
364-
364+
365365
db.collection('t2_5').bulkWrite([
366366
{ insertOne: { a: 1 } }
367367
, { insertMany: [{ g: 1 }, { g: 2 }] }
@@ -396,7 +396,7 @@ exports['should correctly execute insert methods using crud api'] = {
396396
db.collection('t2_6').insertMany([{c:1}, {c:2}, {c:3}], {w:1}, function(err, r) {
397397
test.equal(null, err);
398398
test.equal(3, r.result.n);
399-
399+
400400
db.collection('t2_6').bulkWrite([
401401
{ insertOne: { document: { a: 1 } } }
402402
, { updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
@@ -431,7 +431,7 @@ exports['should correctly execute insert methods using crud api'] = {
431431
db.collection('t2_7').insertMany([{c:1}], {w:1}, function(err, r) {
432432
test.equal(null, err);
433433
test.equal(1, r.result.n);
434-
434+
435435
db.collection('t2_7').bulkWrite([
436436
{ insertOne: { a: 1 } }
437437
, { insertMany: [{ g: 1 }, { g: 2 }] }
@@ -465,7 +465,7 @@ exports['should correctly execute insert methods using crud api'] = {
465465
db.collection('t2_8').insertMany([{c:1}], {w:1}, function(err, r) {
466466
test.equal(null, err);
467467
test.equal(1, r.result.n);
468-
468+
469469
db.collection('t2_8').bulkWrite([
470470
{ insertOne: { document: { a: 1 }} }
471471
, { updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
@@ -502,7 +502,7 @@ exports['should correctly execute update methods using crud api'] = {
502502
// Add a tag that our runner can trigger on
503503
// in this case we are setting that node needs to be higher than 0.10.X to run
504504
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
505-
505+
506506
// The actual test we wish to run
507507
test: function(configuration, test) {
508508
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
@@ -528,7 +528,7 @@ exports['should correctly execute update methods using crud api'] = {
528528
db.collection('t3_2').insertMany([{c:1}], {w:1}, function(err, r) {
529529
test.equal(null, err);
530530
test.equal(1, r.result.n);
531-
531+
532532
db.collection('t3_2').updateOne({ a: 1 }
533533
, { $set: { a: 1 } }
534534
, { upsert: true }, function(err, r) {
@@ -543,7 +543,7 @@ exports['should correctly execute update methods using crud api'] = {
543543
test.equal(1, r.result.n);
544544
test.equal(1, r.matchedCount);
545545
test.ok(r.upsertedId == null);
546-
546+
547547
replaceOne();
548548
});
549549
});
@@ -573,7 +573,7 @@ exports['should correctly execute update methods using crud api'] = {
573573

574574
test.equal(1, r.matchedCount);
575575
test.ok(r.upsertedId == null);
576-
576+
577577
updateMany();
578578
});
579579
});
@@ -586,7 +586,7 @@ exports['should correctly execute update methods using crud api'] = {
586586
db.collection('t3_4').insertMany([{a:1}, {a:1}], {w:1}, function(err, r) {
587587
test.equal(null, err);
588588
test.equal(2, r.result.n);
589-
589+
590590
db.collection('t3_4').updateMany({ a: 1 }
591591
, { $set: { a: 2 } }
592592
, { upsert: true, w: 1 }, function(err, r) {
@@ -601,7 +601,7 @@ exports['should correctly execute update methods using crud api'] = {
601601
test.equal(null, err);
602602
test.equal(1, r.matchedCount);
603603
test.ok(r.upsertedId != null);
604-
604+
605605
db.close();
606606
test.done();
607607
});
@@ -618,7 +618,7 @@ exports['should correctly execute remove methods using crud api'] = {
618618
// Add a tag that our runner can trigger on
619619
// in this case we are setting that node needs to be higher than 0.10.X to run
620620
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
621-
621+
622622
// The actual test we wish to run
623623
test: function(configuration, test) {
624624
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
@@ -632,7 +632,7 @@ exports['should correctly execute remove methods using crud api'] = {
632632
db.collection('t4_1').insertMany([{a:1}, {a:1}], {w:1}, function(err, r) {
633633
test.equal(null, err);
634634
test.equal(2, r.result.n);
635-
635+
636636
db.collection('t4_1').remove({a:1}, {single:true}, function(err, r) {
637637
test.equal(null, err);
638638
test.equal(1, r.result.n);
@@ -655,7 +655,7 @@ exports['should correctly execute remove methods using crud api'] = {
655655
test.equal(null, err);
656656
test.equal(1, r.result.n);
657657
test.equal(1, r.deletedCount);
658-
658+
659659
deleteMany();
660660
});
661661
});
@@ -674,7 +674,7 @@ exports['should correctly execute remove methods using crud api'] = {
674674
test.equal(null, err);
675675
test.equal(2, r.result.n);
676676
test.equal(2, r.deletedCount);
677-
677+
678678
db.close();
679679
test.done();
680680
});
@@ -690,7 +690,7 @@ exports['should correctly execute findAndModify methods using crud api'] = {
690690
// Add a tag that our runner can trigger on
691691
// in this case we are setting that node needs to be higher than 0.10.X to run
692692
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
693-
693+
694694
// The actual test we wish to run
695695
test: function(configuration, test) {
696696
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
@@ -704,7 +704,7 @@ exports['should correctly execute findAndModify methods using crud api'] = {
704704
db.collection('t5_1').insertMany([{a:1, b:1}], {w:1}, function(err, r) {
705705
test.equal(null, err);
706706
test.equal(1, r.result.n);
707-
707+
708708
db.collection('t5_1').findOneAndDelete({a:1}
709709
, { projection: {b:1}, sort: {a:1} }
710710
, function(err, r) {
@@ -724,14 +724,14 @@ exports['should correctly execute findAndModify methods using crud api'] = {
724724
db.collection('t5_2').insertMany([{a:1, b:1}], {w:1}, function(err, r) {
725725
test.equal(null, err);
726726
test.equal(1, r.result.n);
727-
727+
728728
db.collection('t5_2').findOneAndReplace({a:1}
729729
, {c:1, b:1}
730-
, {
730+
, {
731731
projection: {b:1, c:1}
732732
, sort: {a:1}
733733
, returnOriginal: false
734-
, upsert: true
734+
, upsert: true
735735
}
736736
, function(err, r) {
737737
test.equal(null, err);
@@ -751,7 +751,7 @@ exports['should correctly execute findAndModify methods using crud api'] = {
751751
db.collection('t5_3').insertMany([{a:1, b:1}], {w:1}, function(err, r) {
752752
test.equal(null, err);
753753
test.equal(1, r.result.n);
754-
754+
755755
db.collection('t5_3').findOneAndUpdate({a:1}
756756
, {$set: {d:1}}
757757
, {
@@ -781,7 +781,7 @@ exports['should correctly execute removeMany with no selector'] = {
781781
// Add a tag that our runner can trigger on
782782
// in this case we are setting that node needs to be higher than 0.10.X to run
783783
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
784-
784+
785785
// The actual test we wish to run
786786
test: function(configuration, test) {
787787
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
@@ -804,16 +804,16 @@ exports['should correctly execute crud operations with w:0'] = {
804804
// Add a tag that our runner can trigger on
805805
// in this case we are setting that node needs to be higher than 0.10.X to run
806806
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
807-
807+
808808
// The actual test we wish to run
809809
test: function(configuration, test) {
810810
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
811811
// Establish connection to db
812812
db.open(function(err, db) {
813813
test.equal(null, err);
814-
814+
815815
var col = db.collection('shouldCorrectlyExecuteInsertOneWithW0');
816-
816+
817817
col.insertOne({a:1}, {w:0}, function(err,result) {
818818
test.equal(null, err);
819819
test.equal(1, result.result.ok);
@@ -848,4 +848,27 @@ exports['should correctly execute crud operations with w:0'] = {
848848
});
849849
});
850850
}
851-
}
851+
}
852+
853+
exports['should correctly execute updateOne operations with w:0 and upsert'] = {
854+
// Add a tag that our runner can trigger on
855+
// in this case we are setting that node needs to be higher than 0.10.X to run
856+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
857+
858+
// The actual test we wish to run
859+
test: function(configuration, test) {
860+
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
861+
// Establish connection to db
862+
db.open(function(err, db) {
863+
test.equal(null, err);
864+
865+
db.collection('try').updateOne({_id:1}, {$set:{x:1}}, {upsert:true, w:0}, function(err, r) {
866+
test.equal(null, err);
867+
test.equal(0, r.upsertedCount);
868+
869+
db.close();
870+
test.done();
871+
});
872+
});
873+
}
874+
}

0 commit comments

Comments
 (0)