@@ -220,6 +220,10 @@ export class Monitor extends TypedEventEmitter<MonitorEvents> {
220220 return this . rttSamplesMS . min ( ) ;
221221 }
222222
223+ get latestRTT ( ) : number {
224+ return this . rttSamplesMS . last ?? 0 ; // FIXME: Check if this is acceptable
225+ }
226+
223227 addRttSample ( rtt : number ) {
224228 this . rttSamplesMS . addSample ( rtt ) ;
225229 }
@@ -299,12 +303,10 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
299303 hello . isWritablePrimary = hello [ LEGACY_HELLO_COMMAND ] ;
300304 }
301305
302- // FIXME: Figure out how to set this. Should duration be the instantaneous rtt or the averaged
303- // rtt?
306+ // NOTE: here we use the latestRTT as this measurment corresponds with the value
307+ // obtained for this successful heartbeat
304308 const duration =
305- isAwaitable && monitor . rttPinger
306- ? monitor . rttPinger . roundTripTime
307- : calculateDurationInMs ( start ) ;
309+ isAwaitable && monitor . rttPinger ? monitor . rttPinger . latestRTT : calculateDurationInMs ( start ) ;
308310
309311 monitor . emitAndLogHeartbeat (
310312 Server . SERVER_HEARTBEAT_SUCCEEDED ,
@@ -508,6 +510,10 @@ export class RTTPinger {
508510 return this . monitor . minRoundTripTime ;
509511 }
510512
513+ get latestRTT ( ) : number {
514+ return this . monitor . latestRTT ;
515+ }
516+
511517 close ( ) : void {
512518 this . closed = true ;
513519 clearTimeout ( this [ kMonitorId ] ) ;
0 commit comments