@@ -883,3 +883,249 @@ exports['Successfully pass through writeConcern to dropIndexes command'] = {
883
883
} ) ;
884
884
}
885
885
}
886
+
887
+ exports [ 'Successfully pass through writeConcern to createUser command' ] = {
888
+ metadata : {
889
+ requires : {
890
+ generators : true ,
891
+ topology : "single"
892
+ }
893
+ } ,
894
+
895
+ test : function ( configuration , test ) {
896
+ var MongoClient = configuration . require . MongoClient ,
897
+ ObjectId = configuration . require . ObjectId ,
898
+ ReadPreference = configuration . require . ReadPreference ,
899
+ Long = configuration . require . Long ,
900
+ Code = configuration . require . Code ,
901
+ co = require ( 'co' ) ,
902
+ mockupdb = require ( '../mock' ) ;
903
+
904
+ // Contain mock server
905
+ var primaryServer = null ;
906
+ var firstSecondaryServer = null ;
907
+ var arbiterServer = null ;
908
+ var running = true ;
909
+ var electionIds = [ new ObjectId ( ) , new ObjectId ( ) ] ;
910
+
911
+ // Default message fields
912
+ var defaultFields = {
913
+ "setName" : "rs" , "setVersion" : 1 , "electionId" : electionIds [ 0 ] ,
914
+ "maxBsonObjectSize" : 16777216 , "maxMessageSizeBytes" : 48000000 ,
915
+ "maxWriteBatchSize" : 1000 , "localTime" : new Date ( ) , "maxWireVersion" : 5 ,
916
+ "minWireVersion" : 0 , "ok" : 1 , "hosts" : [ "localhost:32000" , "localhost:32001" , "localhost:32002" ] , "arbiters" : [ "localhost:32002" ]
917
+ }
918
+
919
+ // Primary server states
920
+ var primary = [ extend ( defaultFields , {
921
+ "ismaster" :true , "secondary" :false , "me" : "localhost:32000" , "primary" : "localhost:32000" , "tags" : { "loc" : "ny" }
922
+ } ) ] ;
923
+
924
+ // Primary server states
925
+ var firstSecondary = [ extend ( defaultFields , {
926
+ "ismaster" :false , "secondary" :true , "me" : "localhost:32001" , "primary" : "localhost:32000" , "tags" : { "loc" : "sf" }
927
+ } ) ] ;
928
+
929
+ // Primary server states
930
+ var arbiter = [ extend ( defaultFields , {
931
+ "ismaster" :false , "secondary" :false , "arbiterOnly" : true , "me" : "localhost:32002" , "primary" : "localhost:32000"
932
+ } ) ] ;
933
+
934
+ // Boot the mock
935
+ co ( function * ( ) {
936
+ primaryServer = yield mockupdb . createServer ( 32000 , 'localhost' ) ;
937
+ firstSecondaryServer = yield mockupdb . createServer ( 32001 , 'localhost' ) ;
938
+ arbiterServer = yield mockupdb . createServer ( 32002 , 'localhost' ) ;
939
+
940
+ // Primary state machine
941
+ co ( function * ( ) {
942
+ while ( running ) {
943
+ var request = yield primaryServer . receive ( ) ;
944
+ var doc = request . document ;
945
+ // console.log("========================== cmd")
946
+ // console.dir(doc)
947
+
948
+ if ( doc . ismaster ) {
949
+ request . reply ( primary [ 0 ] ) ;
950
+ } else if ( doc . createUser ) {
951
+ commandResult = doc ;
952
+ request . reply ( { ok :1 } ) ;
953
+ }
954
+ }
955
+ } ) . catch ( function ( err ) {
956
+ console . log ( err . stack ) ;
957
+ } ) ;
958
+
959
+ // First secondary state machine
960
+ co ( function * ( ) {
961
+ while ( running ) {
962
+ var request = yield firstSecondaryServer . receive ( ) ;
963
+ var doc = request . document ;
964
+
965
+ if ( doc . ismaster ) {
966
+ request . reply ( firstSecondary [ 0 ] ) ;
967
+ }
968
+ }
969
+ } ) . catch ( function ( err ) {
970
+ console . log ( err . stack ) ;
971
+ } ) ;
972
+
973
+ // Second secondary state machine
974
+ co ( function * ( ) {
975
+ while ( running ) {
976
+ var request = yield arbiterServer . receive ( ) ;
977
+ var doc = request . document ;
978
+
979
+ if ( doc . ismaster ) {
980
+ request . reply ( arbiter [ 0 ] ) ;
981
+ }
982
+ }
983
+ } ) . catch ( function ( err ) {
984
+ console . log ( err . stack ) ;
985
+ } ) ;
986
+ } ) ;
987
+
988
+ var commandResult = null ;
989
+
990
+ // Connect to the mocks
991
+ MongoClient . connect ( 'mongodb://localhost:32000,localhost:32001,localhost:32002/test?replicaSet=rs' , function ( err , db ) {
992
+ test . equal ( null , err ) ;
993
+
994
+ db . admin ( ) . addUser ( 'kay:kay' , 'abc123' , { w :2 , wtimeout :1000 } , function ( err , result ) {
995
+ test . equal ( null , err ) ;
996
+ test . deepEqual ( { w : 2 , wtimeout : 1000 } , commandResult . writeConcern ) ;
997
+
998
+ primaryServer . destroy ( ) ;
999
+ firstSecondaryServer . destroy ( ) ;
1000
+ arbiterServer . destroy ( ) ;
1001
+ running = false ;
1002
+
1003
+ db . close ( ) ;
1004
+ test . done ( ) ;
1005
+ } ) ;
1006
+ } ) ;
1007
+ }
1008
+ }
1009
+
1010
+ exports [ 'Successfully pass through writeConcern to dropUser command' ] = {
1011
+ metadata : {
1012
+ requires : {
1013
+ generators : true ,
1014
+ topology : "single"
1015
+ }
1016
+ } ,
1017
+
1018
+ test : function ( configuration , test ) {
1019
+ var MongoClient = configuration . require . MongoClient ,
1020
+ ObjectId = configuration . require . ObjectId ,
1021
+ ReadPreference = configuration . require . ReadPreference ,
1022
+ Long = configuration . require . Long ,
1023
+ Code = configuration . require . Code ,
1024
+ co = require ( 'co' ) ,
1025
+ mockupdb = require ( '../mock' ) ;
1026
+
1027
+ // Contain mock server
1028
+ var primaryServer = null ;
1029
+ var firstSecondaryServer = null ;
1030
+ var arbiterServer = null ;
1031
+ var running = true ;
1032
+ var electionIds = [ new ObjectId ( ) , new ObjectId ( ) ] ;
1033
+
1034
+ // Default message fields
1035
+ var defaultFields = {
1036
+ "setName" : "rs" , "setVersion" : 1 , "electionId" : electionIds [ 0 ] ,
1037
+ "maxBsonObjectSize" : 16777216 , "maxMessageSizeBytes" : 48000000 ,
1038
+ "maxWriteBatchSize" : 1000 , "localTime" : new Date ( ) , "maxWireVersion" : 5 ,
1039
+ "minWireVersion" : 0 , "ok" : 1 , "hosts" : [ "localhost:32000" , "localhost:32001" , "localhost:32002" ] , "arbiters" : [ "localhost:32002" ]
1040
+ }
1041
+
1042
+ // Primary server states
1043
+ var primary = [ extend ( defaultFields , {
1044
+ "ismaster" :true , "secondary" :false , "me" : "localhost:32000" , "primary" : "localhost:32000" , "tags" : { "loc" : "ny" }
1045
+ } ) ] ;
1046
+
1047
+ // Primary server states
1048
+ var firstSecondary = [ extend ( defaultFields , {
1049
+ "ismaster" :false , "secondary" :true , "me" : "localhost:32001" , "primary" : "localhost:32000" , "tags" : { "loc" : "sf" }
1050
+ } ) ] ;
1051
+
1052
+ // Primary server states
1053
+ var arbiter = [ extend ( defaultFields , {
1054
+ "ismaster" :false , "secondary" :false , "arbiterOnly" : true , "me" : "localhost:32002" , "primary" : "localhost:32000"
1055
+ } ) ] ;
1056
+
1057
+ // Boot the mock
1058
+ co ( function * ( ) {
1059
+ primaryServer = yield mockupdb . createServer ( 32000 , 'localhost' ) ;
1060
+ firstSecondaryServer = yield mockupdb . createServer ( 32001 , 'localhost' ) ;
1061
+ arbiterServer = yield mockupdb . createServer ( 32002 , 'localhost' ) ;
1062
+
1063
+ // Primary state machine
1064
+ co ( function * ( ) {
1065
+ while ( running ) {
1066
+ var request = yield primaryServer . receive ( ) ;
1067
+ var doc = request . document ;
1068
+ // console.log("========================== cmd")
1069
+ // console.dir(doc)
1070
+
1071
+ if ( doc . ismaster ) {
1072
+ request . reply ( primary [ 0 ] ) ;
1073
+ } else if ( doc . dropUser ) {
1074
+ commandResult = doc ;
1075
+ request . reply ( { ok :1 } ) ;
1076
+ }
1077
+ }
1078
+ } ) . catch ( function ( err ) {
1079
+ console . log ( err . stack ) ;
1080
+ } ) ;
1081
+
1082
+ // First secondary state machine
1083
+ co ( function * ( ) {
1084
+ while ( running ) {
1085
+ var request = yield firstSecondaryServer . receive ( ) ;
1086
+ var doc = request . document ;
1087
+
1088
+ if ( doc . ismaster ) {
1089
+ request . reply ( firstSecondary [ 0 ] ) ;
1090
+ }
1091
+ }
1092
+ } ) . catch ( function ( err ) {
1093
+ console . log ( err . stack ) ;
1094
+ } ) ;
1095
+
1096
+ // Second secondary state machine
1097
+ co ( function * ( ) {
1098
+ while ( running ) {
1099
+ var request = yield arbiterServer . receive ( ) ;
1100
+ var doc = request . document ;
1101
+
1102
+ if ( doc . ismaster ) {
1103
+ request . reply ( arbiter [ 0 ] ) ;
1104
+ }
1105
+ }
1106
+ } ) . catch ( function ( err ) {
1107
+ console . log ( err . stack ) ;
1108
+ } ) ;
1109
+ } ) ;
1110
+
1111
+ var commandResult = null ;
1112
+
1113
+ // Connect to the mocks
1114
+ MongoClient . connect ( 'mongodb://localhost:32000,localhost:32001,localhost:32002/test?replicaSet=rs' , function ( err , db ) {
1115
+ test . equal ( null , err ) ;
1116
+
1117
+ db . admin ( ) . removeUser ( 'kay:kay' , { w :2 , wtimeout :1000 } , function ( err , result ) {
1118
+ test . equal ( null , err ) ;
1119
+ test . deepEqual ( { w : 2 , wtimeout : 1000 } , commandResult . writeConcern ) ;
1120
+
1121
+ primaryServer . destroy ( ) ;
1122
+ firstSecondaryServer . destroy ( ) ;
1123
+ arbiterServer . destroy ( ) ;
1124
+ running = false ;
1125
+
1126
+ db . close ( ) ;
1127
+ test . done ( ) ;
1128
+ } ) ;
1129
+ } ) ;
1130
+ }
1131
+ }
0 commit comments