Skip to content

Commit 63d7b52

Browse files
committed
update tests
1 parent 0ce246f commit 63d7b52

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

Diff for: test/unit/sdam/monitor.test.ts

+44-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as sinon from 'sinon';
77
import { setTimeout } from 'timers';
88
import { setTimeout as setTimeoutPromise } from 'timers/promises';
99

10-
import { MongoClient, ServerHeartbeatSucceededEvent } from '../../mongodb';
10+
import { Long, MongoClient, ObjectId, ServerHeartbeatSucceededEvent } from '../../mongodb';
1111
import {
1212
isHello,
1313
LEGACY_HELLO_COMMAND,
@@ -53,10 +53,6 @@ describe('monitoring', function () {
5353

5454
const { major } = coerce(process.version);
5555
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',
6056
'should upgrade to hello from legacy hello when initial handshake contains helloOk'
6157
];
6258
test.skipReason =
@@ -307,7 +303,49 @@ describe('monitoring', function () {
307303
});
308304
});
309305

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');
311349
});
312350

313351
describe('class MonitorInterval', function () {

0 commit comments

Comments
 (0)