@@ -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,33 +46,31 @@ 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 : 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 ) {
61
+ client . connect ( async function ( err , client ) {
62
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
- } ) ;
63
+ const db = client . db ( self . configuration . db ) ;
64
+
65
+ try {
66
+ await db . collection ( 'test' ) . find ( { } ) . toArray ( ) ;
67
+ } catch ( err ) {
68
+ expect ( err ) . to . not . exist ;
69
+ }
70
+
71
+ expect ( test . checkCommand ) . to . containSubset ( {
72
+ $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
73
+ } ) ;
76
74
} ) ;
77
75
}
78
76
} ) ;
@@ -81,36 +79,38 @@ describe('Max Staleness', function () {
81
79
metadata : {
82
80
requires : {
83
81
generators : true ,
84
- topology : 'single '
82
+ topology : 'replicaset '
85
83
}
86
84
} ,
87
85
88
- test : function ( done ) {
86
+ test : async function ( ) {
89
87
const configuration = this . configuration ;
90
88
const client = configuration . newClient ( `mongodb://${ test . server . uri ( ) } /test` , {
91
89
serverApi : null // TODO(NODE-3807): remove resetting serverApi when the usage of mongodb mock server is removed
92
90
} ) ;
93
- client . connect ( function ( err , client ) {
91
+
92
+ try {
93
+ await client . connect ( ) ;
94
+ } catch ( err ) {
94
95
expect ( err ) . to . not . exist ;
96
+ }
95
97
96
- // Get a db with a new readPreference
97
- var db1 = client . db ( 'test' , {
98
- readPreference : new ReadPreference ( 'secondary' , null , { maxStalenessSeconds : 250 } )
99
- } ) ;
98
+ // Get a db with a new readPreference
99
+ const db1 = client . db ( 'test' , {
100
+ readPreference : new ReadPreference ( 'secondary' , null , { maxStalenessSeconds : 250 } )
101
+ } ) ;
100
102
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
- } ) ;
103
+ try {
104
+ await db1 . collection ( 'test' ) . find ( { } ) . toArray ( ) ;
105
+ } catch ( err ) {
106
+ expect ( err ) . to . not . exist ;
107
+ }
108
+
109
+ expect ( test . checkCommand ) . to . containSubset ( {
110
+ $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
113
111
} ) ;
112
+
113
+ client . close ( ) ;
114
114
}
115
115
} ) ;
116
116
@@ -120,35 +120,42 @@ describe('Max Staleness', function () {
120
120
metadata : {
121
121
requires : {
122
122
generators : true ,
123
- topology : 'single '
123
+ topology : 'replicaset '
124
124
}
125
125
} ,
126
126
127
- test : function ( done ) {
128
- var self = this ;
127
+ test : async function ( ) {
128
+ const self = this ;
129
129
const configuration = this . configuration ;
130
130
const client = configuration . newClient ( `mongodb://${ test . server . uri ( ) } /test` , {
131
131
serverApi : null // TODO(NODE-3807): remove resetting serverApi when the usage of mongodb mock server is removed
132
132
} ) ;
133
- client . connect ( function ( err , client ) {
133
+
134
+ try {
135
+ await client . connect ( ) ;
136
+ } catch ( err ) {
134
137
expect ( err ) . to . not . exist ;
135
- var db = client . db ( self . configuration . db ) ;
138
+ }
136
139
140
+ const db = client . db ( self . configuration . db ) ;
141
+
142
+ try {
137
143
// Get a db with a new readPreference
138
- db . collection ( 'test' , {
139
- readPreference : new ReadPreference ( 'secondary' , null , { maxStalenessSeconds : 250 } )
140
- } )
144
+ await db
145
+ . collection ( 'test' , {
146
+ readPreference : new ReadPreference ( 'secondary' , null , { maxStalenessSeconds : 250 } )
147
+ } )
141
148
. 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
- } ) ;
149
+ . toArray ( ) ;
150
+ } catch ( err ) {
151
+ expect ( err ) . to . not . exist ;
152
+ }
153
+
154
+ expect ( test . checkCommand ) . to . containSubset ( {
155
+ $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
151
156
} ) ;
157
+
158
+ client . close ( ) ;
152
159
}
153
160
}
154
161
) ;
@@ -157,35 +164,39 @@ describe('Max Staleness', function () {
157
164
metadata : {
158
165
requires : {
159
166
generators : true ,
160
- topology : 'single '
167
+ topology : 'replicaset '
161
168
}
162
169
} ,
163
170
164
- test : function ( done ) {
165
- var self = this ;
171
+ test : async function ( ) {
172
+ const self = this ;
166
173
const configuration = this . configuration ;
167
174
const client = configuration . newClient ( `mongodb://${ test . server . uri ( ) } /test` , {
168
175
serverApi : null // TODO(NODE-3807): remove resetting serverApi when the usage of mongodb mock server is removed
169
176
} ) ;
170
- client . connect ( function ( err , client ) {
177
+
178
+ try {
179
+ await client . connect ( ) ;
180
+ } catch ( err ) {
171
181
expect ( err ) . to . not . exist ;
172
- var db = client . db ( self . configuration . db ) ;
173
- var readPreference = new ReadPreference ( 'secondary' , null , { maxStalenessSeconds : 250 } ) ;
182
+ }
183
+
184
+ const db = client . db ( self . configuration . db ) ;
185
+ const readPreference = new ReadPreference ( 'secondary' , null , { maxStalenessSeconds : 250 } ) ;
174
186
187
+ try {
175
188
// 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
- } ) ;
189
+ await db . collection ( 'test' ) . find ( { } ) . withReadPreference ( readPreference ) . toArray ( ) ;
190
+ } catch ( err ) {
191
+ expect ( err ) . to . not . exist ;
192
+ }
193
+
194
+ expect ( test . checkCommand ) . to . containSubset ( {
195
+ $query : { find : 'test' , filter : { } } ,
196
+ $readPreference : { mode : 'secondary' , maxStalenessSeconds : 250 }
188
197
} ) ;
198
+
199
+ client . close ( ) ;
189
200
}
190
201
} ) ;
191
202
} ) ;
0 commit comments