@@ -220,6 +220,10 @@ export class Monitor extends TypedEventEmitter<MonitorEvents> {
220
220
return this . rttSamplesMS . min ( ) ;
221
221
}
222
222
223
+ get latestRTT ( ) : number {
224
+ return this . rttSamplesMS . last ?? 0 ; // FIXME: Check if this is acceptable
225
+ }
226
+
223
227
addRttSample ( rtt : number ) {
224
228
this . rttSamplesMS . addSample ( rtt ) ;
225
229
}
@@ -299,12 +303,10 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
299
303
hello . isWritablePrimary = hello [ LEGACY_HELLO_COMMAND ] ;
300
304
}
301
305
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
304
308
const duration =
305
- isAwaitable && monitor . rttPinger
306
- ? monitor . rttPinger . roundTripTime
307
- : calculateDurationInMs ( start ) ;
309
+ isAwaitable && monitor . rttPinger ? monitor . rttPinger . latestRTT : calculateDurationInMs ( start ) ;
308
310
309
311
monitor . emitAndLogHeartbeat (
310
312
Server . SERVER_HEARTBEAT_SUCCEEDED ,
@@ -508,6 +510,10 @@ export class RTTPinger {
508
510
return this . monitor . minRoundTripTime ;
509
511
}
510
512
513
+ get latestRTT ( ) : number {
514
+ return this . monitor . latestRTT ;
515
+ }
516
+
511
517
close ( ) : void {
512
518
this . closed = true ;
513
519
clearTimeout ( this [ kMonitorId ] ) ;
0 commit comments