File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -172,6 +172,9 @@ function monitorServer(server, options) {
172172 return callback ( err , null ) ;
173173 }
174174
175+ // save round trip time
176+ server . description . roundTripTime = duration ;
177+
175178 const isMaster = result . result ;
176179 server . emit (
177180 'serverHeartbeatSucceeded' ,
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const mock = require ( 'mongodb-mock-server' ) ;
3+ const Topology = require ( '../../../lib/core/sdam/topology' ) . Topology ;
4+ const expect = require ( 'chai' ) . expect ;
5+
6+ describe ( 'monitoring' , function ( ) {
7+ let server ;
8+
9+ after ( ( ) => mock . cleanup ( ) ) ;
10+ beforeEach ( function ( ) {
11+ return mock . createServer ( ) . then ( _server => ( server = _server ) ) ;
12+ } ) ;
13+
14+ it ( 'should record roundTripTime' , function ( done ) {
15+ server . setMessageHandler ( request => {
16+ const doc = request . document ;
17+ if ( doc . ismaster ) {
18+ request . reply ( Object . assign ( { } , mock . DEFAULT_ISMASTER ) ) ;
19+ } else if ( doc . endSessions ) {
20+ request . reply ( { ok : 1 } ) ;
21+ }
22+ } ) ;
23+
24+ // set `heartbeatFrequencyMS` to 250ms to force a quick monitoring check, and wait 500ms to validate below
25+ const topology = new Topology ( server . uri ( ) , { heartbeatFrequencyMS : 250 } ) ;
26+ topology . connect ( err => {
27+ expect ( err ) . to . not . exist ;
28+
29+ setTimeout ( ( ) => {
30+ expect ( topology )
31+ . property ( 'description' )
32+ . property ( 'servers' )
33+ . to . have . length ( 1 ) ;
34+
35+ const serverDescription = Array . from ( topology . description . servers . values ( ) ) [ 0 ] ;
36+ expect ( serverDescription )
37+ . property ( 'roundTripTime' )
38+ . to . be . greaterThan ( 0 ) ;
39+
40+ topology . close ( done ) ;
41+ } , 500 ) ;
42+ } ) ;
43+ } ) ;
44+ } ) ;
You can’t perform that action at this time.
0 commit comments