@@ -304,4 +304,50 @@ describe('Write Concern', function () {
304304 }
305305 } ) ;
306306 } ) ;
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+ beforeEach ( async function ( ) {
313+ client = this . configuration . newClient ( { } , { monitorCommands : true } ) ;
314+ client . on ( 'commandStarted' , filterForCommands ( 'insert' , commands ) ) ;
315+ collection = client . db ( 'foo' ) . collection ( 'bar' ) ;
316+ } )
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 ( { name : 'john doe' } , { timeoutMS : 1000 , writeConcern : { wtimeout : 1000 } } ) ;
327+ const [
328+ {
329+ command : {
330+ writeConcern
331+ }
332+ }
333+ ] = commands ;
334+ expect ( writeConcern ) . not . to . exist ;
335+ } )
336+ } )
337+
338+ context ( 'when the write concern includes only non-timeout values (`w`)' , function ( ) {
339+ it ( 'the writeConcern is added to the command.' , async function ( ) {
340+ await collection . insertOne ( { name : 'john doe' } , { timeoutMS : 1000 , writeConcern : { wtimeout : 1000 , w : 'majority' } } ) ;
341+ const [
342+ {
343+ command : {
344+ writeConcern
345+ }
346+ }
347+ ] = commands ;
348+ expect ( writeConcern ) . to . deep . equal ( { w : 'majority' } )
349+ } )
350+
351+ } )
352+ } )
307353} ) ;
0 commit comments