@@ -18,7 +18,7 @@ describe('Max Staleness', function () {
1818      // Primary server states 
1919      const  serverIsPrimary  =  [ Object . assign ( { } ,  defaultFields ) ] ; 
2020      server . setMessageHandler ( request  =>  { 
21-         var  doc  =  request . document ; 
21+         const  doc  =  request . document ; 
2222        if  ( isHello ( doc ) )  { 
2323          request . reply ( serverIsPrimary [ 0 ] ) ; 
2424          return ; 
@@ -46,71 +46,53 @@ describe('Max Staleness', function () {
4646    metadata : { 
4747      requires : { 
4848        generators : true , 
49-         topology : 'single ' 
49+         topology : 'replicaset ' 
5050      } 
5151    } , 
5252
53-     test : function  ( done )  { 
54-       var  self  =  this ; 
53+     test : async   function  ( )  { 
54+       const  self  =  this ; 
5555      const  configuration  =  this . configuration ; 
5656      const  client  =  configuration . newClient ( 
5757        `mongodb://${ test . server . uri ( ) }  , 
5858        {  serverApi : null  }  // TODO(NODE-3807): remove resetting serverApi when the usage of mongodb mock server is removed 
5959      ) ; 
6060
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  } 
7666      } ) ; 
67+       await  client . close ( ) ; 
7768    } 
7869  } ) ; 
7970
8071  it ( 'should correctly set maxStalenessSeconds on Mongos query using db level readPreference' ,  { 
8172    metadata : { 
8273      requires : { 
8374        generators : true , 
84-         topology : 'single ' 
75+         topology : 'replicaset ' 
8576      } 
8677    } , 
8778
88-     test : function  ( done )  { 
79+     test : async   function  ( )  { 
8980      const  configuration  =  this . configuration ; 
9081      const  client  =  configuration . newClient ( `mongodb://${ test . server . uri ( ) }  ,  { 
9182        serverApi : null  // TODO(NODE-3807): remove resetting serverApi when the usage of mongodb mock server is removed 
9283      } ) ; 
93-       client . connect ( function  ( err ,  client )  { 
94-         expect ( err ) . to . not . exist ; 
9584
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 ( ) ; 
10086
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  } 
11394      } ) ; 
95+       await  client . close ( ) ; 
11496    } 
11597  } ) ; 
11698
@@ -120,35 +102,31 @@ describe('Max Staleness', function () {
120102      metadata : { 
121103        requires : { 
122104          generators : true , 
123-           topology : 'single ' 
105+           topology : 'replicaset ' 
124106        } 
125107      } , 
126108
127-       test : function  ( done )  { 
128-         var  self  =  this ; 
109+       test : async   function  ( )  { 
110+         const  self  =  this ; 
129111        const  configuration  =  this . configuration ; 
130112        const  client  =  configuration . newClient ( `mongodb://${ test . server . uri ( ) }  ,  { 
131113          serverApi : null  // TODO(NODE-3807): remove resetting serverApi when the usage of mongodb mock server is removed 
132114        } ) ; 
133-         client . connect ( function  ( err ,  client )  { 
134-           expect ( err ) . to . not . exist ; 
135-           var  db  =  client . db ( self . configuration . db ) ; 
136115
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' ,  { 
139122            readPreference : new  ReadPreference ( 'secondary' ,  null ,  {  maxStalenessSeconds : 250  } ) 
140123          } ) 
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  } 
151128        } ) ; 
129+         await  client . close ( ) ; 
152130      } 
153131    } 
154132  ) ; 
@@ -157,35 +135,29 @@ describe('Max Staleness', function () {
157135    metadata : { 
158136      requires : { 
159137        generators : true , 
160-         topology : 'single ' 
138+         topology : 'replicaset ' 
161139      } 
162140    } , 
163141
164-     test : function  ( done )  { 
165-       var  self  =  this ; 
142+     test : async   function  ( )  { 
143+       const  self  =  this ; 
166144      const  configuration  =  this . configuration ; 
167145      const  client  =  configuration . newClient ( `mongodb://${ test . server . uri ( ) }  ,  { 
168146        serverApi : null  // TODO(NODE-3807): remove resetting serverApi when the usage of mongodb mock server is removed 
169147      } ) ; 
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  } ) ; 
174148
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  } 
188159      } ) ; 
160+       await  client . close ( ) ; 
189161    } 
190162  } ) ; 
191163} ) ; 
0 commit comments