1
1
'use strict' ;
2
+
2
3
const expect = require ( 'chai' ) . expect ;
3
4
const setupDatabase = require ( './shared' ) . setupDatabase ;
5
+ const withMonitoredClient = require ( './shared' ) . withMonitoredClient ;
4
6
const TestRunnerContext = require ( './spec-runner' ) . TestRunnerContext ;
5
7
const generateTopologyTests = require ( './spec-runner' ) . generateTopologyTests ;
6
8
const loadSpecTests = require ( '../spec' ) . loadSpecTests ;
@@ -43,7 +45,7 @@ describe('Sessions', function () {
43
45
44
46
it ( 'should send endSessions for multiple sessions' , {
45
47
metadata : {
46
- requires : { topology : [ 'single' ] , mongodb : '>3.6.0' } ,
48
+ requires : { topology : [ 'single' ] , mongodb : '>= 3.6.0' } ,
47
49
// Skipping session leak tests b/c these are explicit sessions
48
50
sessions : { skipLeakTests : true }
49
51
} ,
@@ -65,7 +67,7 @@ describe('Sessions', function () {
65
67
} ) ;
66
68
67
69
describe ( 'withSession' , {
68
- metadata : { requires : { mongodb : '>3.6.0' } } ,
70
+ metadata : { requires : { mongodb : '>= 3.6.0' } } ,
69
71
test : function ( ) {
70
72
beforeEach ( function ( ) {
71
73
return test . setup ( this . configuration ) ;
@@ -194,4 +196,44 @@ describe('Sessions', function () {
194
196
195
197
generateTopologyTests ( testSuites , testContext , testFilter ) ;
196
198
} ) ;
199
+
200
+ context ( 'unacknowledged writes' , ( ) => {
201
+ it ( 'should not include session for unacknowledged writes' , {
202
+ metadata : { requires : { topology : 'single' , mongodb : '>=3.6.0' } } ,
203
+ test : withMonitoredClient ( 'insert' , { clientOptions : { w : 0 } } , function (
204
+ client ,
205
+ events ,
206
+ done
207
+ ) {
208
+ client
209
+ . db ( 'test' )
210
+ . collection ( 'foo' )
211
+ . insertOne ( { foo : 'bar' } , err => {
212
+ expect ( err ) . to . not . exist ;
213
+ const event = events [ 0 ] ;
214
+ expect ( event ) . nested . property ( 'command.writeConcern.w' ) . to . equal ( 0 ) ;
215
+ expect ( event ) . to . not . have . nested . property ( 'command.lsid' ) ;
216
+ done ( ) ;
217
+ } ) ;
218
+ } )
219
+ } ) ;
220
+ it ( 'should throw error with explicit session' , {
221
+ metadata : { requires : { topology : 'replicaset' , mongodb : '>=3.6.0' } } ,
222
+ test : withMonitoredClient ( 'insert' , { clientOptions : { w : 0 } } , function (
223
+ client ,
224
+ events ,
225
+ done
226
+ ) {
227
+ const session = client . startSession ( { causalConsistency : true } ) ;
228
+ client
229
+ . db ( 'test' )
230
+ . collection ( 'foo' )
231
+ . insertOne ( { foo : 'bar' } , { session } , err => {
232
+ expect ( err ) . to . exist ;
233
+ expect ( err . message ) . to . equal ( 'Cannot have explicit session with unacknowledged writes' ) ;
234
+ client . close ( done ) ;
235
+ } ) ;
236
+ } )
237
+ } ) ;
238
+ } ) ;
197
239
} ) ;
0 commit comments