@@ -18,7 +18,7 @@ describe('Max Staleness', function () {
18
18
// Primary server states
19
19
const serverIsPrimary = [ Object . assign ( { } , defaultFields ) ] ;
20
20
server . setMessageHandler ( request => {
21
- var doc = request . document ;
21
+ const doc = request . document ;
22
22
if ( isHello ( doc ) ) {
23
23
request . reply ( serverIsPrimary [ 0 ] ) ;
24
24
return ;
@@ -46,71 +46,53 @@ describe('Max Staleness', function () {
46
46
metadata : {
47
47
requires : {
48
48
generators : true ,
49
- topology : 'single '
49
+ topology : 'replicaset '
50
50
}
51
51
} ,
52
52
53
- test : function ( done ) {
54
- var self = this ;
53
+ test : async function ( ) {
54
+ const self = this ;
55
55
const configuration = this . configuration ;
56
56
const client = configuration . newClient (
57
57
`mongodb://${ test . server . uri ( ) } /test?readPreference=secondary&maxStalenessSeconds=250` ,
58
58
{ serverApi : null } // TODO(NODE-3807): remove resetting serverApi when the usage of mongodb mock server is removed
59
59
) ;
60
60
61
- client . connect ( function ( err , client ) {
62
- expect ( err ) . to . not . exist ;
63
- var db = client . db ( self . configuration . db ) ;
64
-
65
- db . collection ( 'test' )
66
- . find ( { } )
67
- . toArray ( function ( err ) {
68
- expect ( err ) . to . not . exist ;
69
- expect ( test . checkCommand ) . to . containSubset ( {
70
- $query : { find : 'test' , filter : { } } ,
71
- $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
72
- } ) ;
73
-
74
- client . close ( done ) ;
75
- } ) ;
61
+ await client . connect ( ) ;
62
+ const db = client . db ( self . configuration . db ) ;
63
+ await db . collection ( 'test' ) . find ( { } ) . toArray ( ) ;
64
+ expect ( test . checkCommand ) . to . containSubset ( {
65
+ $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
76
66
} ) ;
67
+ await client . close ( ) ;
77
68
}
78
69
} ) ;
79
70
80
71
it ( 'should correctly set maxStalenessSeconds on Mongos query using db level readPreference' , {
81
72
metadata : {
82
73
requires : {
83
74
generators : true ,
84
- topology : 'single '
75
+ topology : 'replicaset '
85
76
}
86
77
} ,
87
78
88
- test : function ( done ) {
79
+ test : async function ( ) {
89
80
const configuration = this . configuration ;
90
81
const client = configuration . newClient ( `mongodb://${ test . server . uri ( ) } /test` , {
91
82
serverApi : null // TODO(NODE-3807): remove resetting serverApi when the usage of mongodb mock server is removed
92
83
} ) ;
93
- client . connect ( function ( err , client ) {
94
- expect ( err ) . to . not . exist ;
95
84
96
- // Get a db with a new readPreference
97
- var db1 = client . db ( 'test' , {
98
- readPreference : new ReadPreference ( 'secondary' , null , { maxStalenessSeconds : 250 } )
99
- } ) ;
85
+ await client . connect ( ) ;
100
86
101
- db1
102
- . collection ( 'test' )
103
- . find ( { } )
104
- . toArray ( function ( err ) {
105
- expect ( err ) . to . not . exist ;
106
- expect ( test . checkCommand ) . to . containSubset ( {
107
- $query : { find : 'test' , filter : { } } ,
108
- $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
109
- } ) ;
110
-
111
- client . close ( done ) ;
112
- } ) ;
87
+ // Get a db with a new readPreference
88
+ const db1 = client . db ( 'test' , {
89
+ readPreference : new ReadPreference ( 'secondary' , null , { maxStalenessSeconds : 250 } )
90
+ } ) ;
91
+ await db1 . collection ( 'test' ) . find ( { } ) . toArray ( ) ;
92
+ expect ( test . checkCommand ) . to . containSubset ( {
93
+ $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
113
94
} ) ;
95
+ await client . close ( ) ;
114
96
}
115
97
} ) ;
116
98
@@ -120,35 +102,31 @@ describe('Max Staleness', function () {
120
102
metadata : {
121
103
requires : {
122
104
generators : true ,
123
- topology : 'single '
105
+ topology : 'replicaset '
124
106
}
125
107
} ,
126
108
127
- test : function ( done ) {
128
- var self = this ;
109
+ test : async function ( ) {
110
+ const self = this ;
129
111
const configuration = this . configuration ;
130
112
const client = configuration . newClient ( `mongodb://${ test . server . uri ( ) } /test` , {
131
113
serverApi : null // TODO(NODE-3807): remove resetting serverApi when the usage of mongodb mock server is removed
132
114
} ) ;
133
- client . connect ( function ( err , client ) {
134
- expect ( err ) . to . not . exist ;
135
- var db = client . db ( self . configuration . db ) ;
136
115
137
- // Get a db with a new readPreference
138
- db . collection ( 'test' , {
116
+ await client . connect ( ) ;
117
+ const db = client . db ( self . configuration . db ) ;
118
+
119
+ // Get a db with a new readPreference
120
+ await db
121
+ . collection ( 'test' , {
139
122
readPreference : new ReadPreference ( 'secondary' , null , { maxStalenessSeconds : 250 } )
140
123
} )
141
- . find ( { } )
142
- . toArray ( function ( err ) {
143
- expect ( err ) . to . not . exist ;
144
- expect ( test . checkCommand ) . to . containSubset ( {
145
- $query : { find : 'test' , filter : { } } ,
146
- $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
147
- } ) ;
148
-
149
- client . close ( done ) ;
150
- } ) ;
124
+ . find ( { } )
125
+ . toArray ( ) ;
126
+ expect ( test . checkCommand ) . to . containSubset ( {
127
+ $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
151
128
} ) ;
129
+ await client . close ( ) ;
152
130
}
153
131
}
154
132
) ;
@@ -157,35 +135,29 @@ describe('Max Staleness', function () {
157
135
metadata : {
158
136
requires : {
159
137
generators : true ,
160
- topology : 'single '
138
+ topology : 'replicaset '
161
139
}
162
140
} ,
163
141
164
- test : function ( done ) {
165
- var self = this ;
142
+ test : async function ( ) {
143
+ const self = this ;
166
144
const configuration = this . configuration ;
167
145
const client = configuration . newClient ( `mongodb://${ test . server . uri ( ) } /test` , {
168
146
serverApi : null // TODO(NODE-3807): remove resetting serverApi when the usage of mongodb mock server is removed
169
147
} ) ;
170
- client . connect ( function ( err , client ) {
171
- expect ( err ) . to . not . exist ;
172
- var db = client . db ( self . configuration . db ) ;
173
- var readPreference = new ReadPreference ( 'secondary' , null , { maxStalenessSeconds : 250 } ) ;
174
148
175
- // Get a db with a new readPreference
176
- db . collection ( 'test' )
177
- . find ( { } )
178
- . withReadPreference ( readPreference )
179
- . toArray ( function ( err ) {
180
- expect ( err ) . to . not . exist ;
181
- expect ( test . checkCommand ) . to . containSubset ( {
182
- $query : { find : 'test' , filter : { } } ,
183
- $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
184
- } ) ;
185
-
186
- client . close ( done ) ;
187
- } ) ;
149
+ await client . connect ( ) ;
150
+ const db = client . db ( self . configuration . db ) ;
151
+ const readPreference = new ReadPreference ( 'secondary' , null , { maxStalenessSeconds : 250 } ) ;
152
+
153
+ // Get a db with a new readPreference
154
+ await db . collection ( 'test' ) . find ( { } ) . withReadPreference ( readPreference ) . toArray ( ) ;
155
+
156
+ expect ( test . checkCommand ) . to . containSubset ( {
157
+ $query : { find : 'test' , filter : { } } ,
158
+ $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
188
159
} ) ;
160
+ await client . close ( ) ;
189
161
}
190
162
} ) ;
191
163
} ) ;
0 commit comments