@@ -4,9 +4,12 @@ const Topology = require('../../lib/core/sdam/topology').Topology;
44const test = require ( './shared' ) . assert ;
55const setupDatabase = require ( './shared' ) . setupDatabase ;
66const withMonitoredClient = require ( './shared' ) . withMonitoredClient ;
7- const expect = require ( 'chai' ) . expect ;
7+
88const ReadPreference = require ( '../../lib/core/topologies/read_preference' ) ;
99const withClient = require ( './shared' ) . withClient ;
10+ const chai = require ( 'chai' ) ;
11+ chai . use ( require ( 'chai-subset' ) ) ;
12+ const expect = chai . expect ;
1013
1114describe ( 'ReadPreference' , function ( ) {
1215 before ( function ( ) {
@@ -730,13 +733,30 @@ describe('ReadPreference', function() {
730733 } ) ;
731734 } ) ;
732735
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+ ) {
738743 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+ } )
741761 } ) ;
742762} ) ;
0 commit comments