@@ -7,7 +7,7 @@ import * as sinon from 'sinon';
7
7
import { setTimeout } from 'timers' ;
8
8
import { setTimeout as setTimeoutPromise } from 'timers/promises' ;
9
9
10
- import { MongoClient , ServerHeartbeatSucceededEvent } from '../../mongodb' ;
10
+ import { Long , MongoClient , ObjectId , ServerHeartbeatSucceededEvent } from '../../mongodb' ;
11
11
import {
12
12
isHello ,
13
13
LEGACY_HELLO_COMMAND ,
@@ -53,10 +53,6 @@ describe('monitoring', function () {
53
53
54
54
const { major } = coerce ( process . version ) ;
55
55
const failingTests = [
56
- 'should connect and issue an initial server check' ,
57
- 'should ignore attempts to connect when not already closed' ,
58
- 'should not initiate another check if one is in progress' ,
59
- 'should not close the monitor on a failed heartbeat' ,
60
56
'should upgrade to hello from legacy hello when initial handshake contains helloOk'
61
57
] ;
62
58
test . skipReason =
@@ -307,7 +303,49 @@ describe('monitoring', function () {
307
303
} ) ;
308
304
} ) ;
309
305
310
- describe ( '' ) ;
306
+ describe ( 'roundTripTime' , function ( ) {
307
+ const table = [
308
+ {
309
+ serverMonitoringMode : 'stream' ,
310
+ topologyVersion : {
311
+ processId : new ObjectId ( ) ,
312
+ counter : new Long ( 0 , 0 )
313
+ }
314
+ } ,
315
+ { serverMonitoringMode : 'poll' , topologyVersion : undefined }
316
+ ] ;
317
+ for ( const { serverMonitoringMode, topologyVersion } of table ) {
318
+ context ( `when serverMonitoringMode = ${ serverMonitoringMode } ` , ( ) => {
319
+ context ( 'when more than one heartbeatSucceededEvent has been captured' , ( ) => {
320
+ const heartbeatDurationMS = 250 ;
321
+ it ( 'correctly returns the mean of the heartbeat durations' , async ( ) => {
322
+ mockServer . setMessageHandler ( request => {
323
+ setTimeout (
324
+ ( ) => request . reply ( Object . assign ( { helloOk : true } , mock . HELLO ) ) ,
325
+ heartbeatDurationMS
326
+ ) ;
327
+ } ) ;
328
+ const server = new MockServer ( mockServer . address ( ) ) ;
329
+ if ( topologyVersion ) server . description . topologyVersion = topologyVersion ;
330
+ monitor = new Monitor ( server as any , { serverMonitoringMode } as any ) ;
331
+ monitor . connect ( ) ;
332
+
333
+ for ( let i = 0 ; i < 5 ; i ++ ) {
334
+ await once ( monitor , 'serverHeartbeatSucceeded' ) ;
335
+ monitor . requestCheck ( ) ;
336
+ console . log ( i ) ;
337
+ }
338
+ monitor . close ( ) ;
339
+
340
+ console . log ( monitor . rttSamplesMS . samples ) ;
341
+ expect ( monitor . roundTripTime ) . to . be . greaterThanOrEqual ( heartbeatDurationMS ) ;
342
+ } ) ;
343
+ } ) ;
344
+ } ) ;
345
+ }
346
+ } ) ;
347
+
348
+ //describe('minRoundTripTime');
311
349
} ) ;
312
350
313
351
describe ( 'class MonitorInterval' , function ( ) {
0 commit comments