@@ -4,9 +4,12 @@ const Topology = require('../../lib/core/sdam/topology').Topology;
4
4
const test = require ( './shared' ) . assert ;
5
5
const setupDatabase = require ( './shared' ) . setupDatabase ;
6
6
const withMonitoredClient = require ( './shared' ) . withMonitoredClient ;
7
- const expect = require ( 'chai' ) . expect ;
7
+
8
8
const ReadPreference = require ( '../../lib/core/topologies/read_preference' ) ;
9
9
const withClient = require ( './shared' ) . withClient ;
10
+ const chai = require ( 'chai' ) ;
11
+ chai . use ( require ( 'chai-subset' ) ) ;
12
+ const expect = chai . expect ;
10
13
11
14
describe ( 'ReadPreference' , function ( ) {
12
15
before ( function ( ) {
@@ -730,13 +733,30 @@ describe('ReadPreference', function() {
730
733
} ) ;
731
734
} ) ;
732
735
733
- it ( 'should respect readPreference from uri' , function ( done ) {
734
- const configuration = this . configuration ;
735
- const client = configuration . newClient ( `${ configuration . url ( ) } ?readPreference=secondary` ) ;
736
- client . connect ( err => {
737
- expect ( err ) . to . not . exist ;
736
+ it ( 'should respect readPreference from uri' , {
737
+ metadata : { requires : { topology : 'replicaset' , mongodb : '>=3.6' } } ,
738
+ test : withMonitoredClient ( 'find' , { queryOptions : { readPreference : 'secondary' } } , function (
739
+ client ,
740
+ events ,
741
+ done
742
+ ) {
738
743
expect ( client . readPreference . mode ) . to . equal ( 'secondary' ) ;
739
- client . close ( done ) ;
740
- } ) ;
744
+ client
745
+ . db ( 'test' )
746
+ . collection ( 'test' )
747
+ . findOne ( { a : 1 } , err => {
748
+ expect ( err ) . to . not . exist ;
749
+ expect ( events )
750
+ . to . be . an ( 'array' )
751
+ . with . lengthOf ( 1 ) ;
752
+ expect ( events [ 0 ] ) . to . containSubset ( {
753
+ commandName : 'find' ,
754
+ command : {
755
+ $readPreference : { mode : 'secondary' }
756
+ }
757
+ } ) ;
758
+ done ( ) ;
759
+ } ) ;
760
+ } )
741
761
} ) ;
742
762
} ) ;
0 commit comments