@@ -304,4 +304,51 @@ describe('Write Concern', function () {
304
304
}
305
305
} ) ;
306
306
} ) ;
307
+
308
+ describe ( 'NODE-6763: write concern is still added with timeoutMS is set' , function ( ) {
309
+ let client : MongoClient ;
310
+ let collection : Collection ;
311
+ const commands : CommandStartedEvent [ ] = [ ] ;
312
+
313
+ beforeEach ( async function ( ) {
314
+ client = this . configuration . newClient ( { } , { monitorCommands : true } ) ;
315
+ client . on ( 'commandStarted' , filterForCommands ( 'insert' , commands ) ) ;
316
+ collection = client . db ( 'foo' ) . collection ( 'bar' ) ;
317
+ } ) ;
318
+
319
+ afterEach ( async function ( ) {
320
+ await client . close ( ) ;
321
+ commands . length = 0 ;
322
+ } ) ;
323
+
324
+ context ( 'when the write concern includes only timeouts' , function ( ) {
325
+ it ( 'the writeConcern is not added to the command.' , async function ( ) {
326
+ await collection . insertOne (
327
+ { name : 'john doe' } ,
328
+ { timeoutMS : 1000 , writeConcern : { wtimeout : 1000 } }
329
+ ) ;
330
+ const [
331
+ {
332
+ command : { writeConcern }
333
+ }
334
+ ] = commands ;
335
+ expect ( writeConcern ) . not . to . exist ;
336
+ } ) ;
337
+ } ) ;
338
+
339
+ context ( 'when the write concern includes only non-timeout values (`w`)' , function ( ) {
340
+ it ( 'the writeConcern is added to the command.' , async function ( ) {
341
+ await collection . insertOne (
342
+ { name : 'john doe' } ,
343
+ { timeoutMS : 1000 , writeConcern : { wtimeout : 1000 , w : 'majority' } }
344
+ ) ;
345
+ const [
346
+ {
347
+ command : { writeConcern }
348
+ }
349
+ ] = commands ;
350
+ expect ( writeConcern ) . to . deep . equal ( { w : 'majority' } ) ;
351
+ } ) ;
352
+ } ) ;
353
+ } ) ;
307
354
} ) ;
0 commit comments