@@ -1129,3 +1129,127 @@ exports['Successfully pass through writeConcern to dropUser command'] = {
1129
1129
} ) ;
1130
1130
}
1131
1131
}
1132
+
1133
+ exports [ 'Successfully pass through writeConcern to findAndModify command' ] = {
1134
+ metadata : {
1135
+ requires : {
1136
+ generators : true ,
1137
+ topology : "single"
1138
+ }
1139
+ } ,
1140
+
1141
+ test : function ( configuration , test ) {
1142
+ var MongoClient = configuration . require . MongoClient ,
1143
+ ObjectId = configuration . require . ObjectId ,
1144
+ ReadPreference = configuration . require . ReadPreference ,
1145
+ Long = configuration . require . Long ,
1146
+ Code = configuration . require . Code ,
1147
+ co = require ( 'co' ) ,
1148
+ mockupdb = require ( '../mock' ) ;
1149
+
1150
+ // Contain mock server
1151
+ var primaryServer = null ;
1152
+ var firstSecondaryServer = null ;
1153
+ var arbiterServer = null ;
1154
+ var running = true ;
1155
+ var electionIds = [ new ObjectId ( ) , new ObjectId ( ) ] ;
1156
+
1157
+ // Default message fields
1158
+ var defaultFields = {
1159
+ "setName" : "rs" , "setVersion" : 1 , "electionId" : electionIds [ 0 ] ,
1160
+ "maxBsonObjectSize" : 16777216 , "maxMessageSizeBytes" : 48000000 ,
1161
+ "maxWriteBatchSize" : 1000 , "localTime" : new Date ( ) , "maxWireVersion" : 5 ,
1162
+ "minWireVersion" : 0 , "ok" : 1 , "hosts" : [ "localhost:32000" , "localhost:32001" , "localhost:32002" ] , "arbiters" : [ "localhost:32002" ]
1163
+ }
1164
+
1165
+ // Primary server states
1166
+ var primary = [ extend ( defaultFields , {
1167
+ "ismaster" :true , "secondary" :false , "me" : "localhost:32000" , "primary" : "localhost:32000" , "tags" : { "loc" : "ny" }
1168
+ } ) ] ;
1169
+
1170
+ // Primary server states
1171
+ var firstSecondary = [ extend ( defaultFields , {
1172
+ "ismaster" :false , "secondary" :true , "me" : "localhost:32001" , "primary" : "localhost:32000" , "tags" : { "loc" : "sf" }
1173
+ } ) ] ;
1174
+
1175
+ // Primary server states
1176
+ var arbiter = [ extend ( defaultFields , {
1177
+ "ismaster" :false , "secondary" :false , "arbiterOnly" : true , "me" : "localhost:32002" , "primary" : "localhost:32000"
1178
+ } ) ] ;
1179
+
1180
+ // Boot the mock
1181
+ co ( function * ( ) {
1182
+ primaryServer = yield mockupdb . createServer ( 32000 , 'localhost' ) ;
1183
+ firstSecondaryServer = yield mockupdb . createServer ( 32001 , 'localhost' ) ;
1184
+ arbiterServer = yield mockupdb . createServer ( 32002 , 'localhost' ) ;
1185
+
1186
+ // Primary state machine
1187
+ co ( function * ( ) {
1188
+ while ( running ) {
1189
+ var request = yield primaryServer . receive ( ) ;
1190
+ var doc = request . document ;
1191
+ // console.log("========================== cmd")
1192
+ // console.dir(doc)
1193
+
1194
+ if ( doc . ismaster ) {
1195
+ request . reply ( primary [ 0 ] ) ;
1196
+ } else if ( doc . findandmodify ) {
1197
+ commandResult = doc ;
1198
+ request . reply ( { ok :1 , result : { } } ) ;
1199
+ }
1200
+ }
1201
+ } ) . catch ( function ( err ) {
1202
+ console . log ( err . stack ) ;
1203
+ } ) ;
1204
+
1205
+ // First secondary state machine
1206
+ co ( function * ( ) {
1207
+ while ( running ) {
1208
+ var request = yield firstSecondaryServer . receive ( ) ;
1209
+ var doc = request . document ;
1210
+
1211
+ if ( doc . ismaster ) {
1212
+ request . reply ( firstSecondary [ 0 ] ) ;
1213
+ }
1214
+ }
1215
+ } ) . catch ( function ( err ) {
1216
+ console . log ( err . stack ) ;
1217
+ } ) ;
1218
+
1219
+ // Second secondary state machine
1220
+ co ( function * ( ) {
1221
+ while ( running ) {
1222
+ var request = yield arbiterServer . receive ( ) ;
1223
+ var doc = request . document ;
1224
+
1225
+ if ( doc . ismaster ) {
1226
+ request . reply ( arbiter [ 0 ] ) ;
1227
+ }
1228
+ }
1229
+ } ) . catch ( function ( err ) {
1230
+ console . log ( err . stack ) ;
1231
+ } ) ;
1232
+ } ) ;
1233
+
1234
+ var commandResult = null ;
1235
+
1236
+ // Connect to the mocks
1237
+ MongoClient . connect ( 'mongodb://localhost:32000,localhost:32001,localhost:32002/test?replicaSet=rs' , function ( err , db ) {
1238
+ test . equal ( null , err ) ;
1239
+
1240
+ // Simple findAndModify command returning the new document
1241
+ db . collection ( 'test' ) . findAndModify ( { a :1 } , [ [ 'a' , 1 ] ] , { $set :{ b1 :1 } } , { new :true , w :2 , wtimeout :1000 } , function ( err , doc ) {
1242
+ test . equal ( null , err ) ;
1243
+ test . deepEqual ( { w : 2 , wtimeout : 1000 } , commandResult . writeConcern ) ;
1244
+
1245
+ primaryServer . destroy ( ) ;
1246
+ firstSecondaryServer . destroy ( ) ;
1247
+ arbiterServer . destroy ( ) ;
1248
+ running = false ;
1249
+
1250
+ db . close ( ) ;
1251
+ test . done ( ) ;
1252
+ } ) ;
1253
+ } ) ;
1254
+ }
1255
+ }
0 commit comments