Skip to content

Commit 5d8bf78

Browse files
committed
test(DRVIERS-2677): Update prose tests
1 parent efece79 commit 5d8bf78

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/integration/server-discovery-and-monitoring/server_discovery_and_monitoring.prose.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { expect } from 'chai';
22
import { once } from 'events';
3+
import * as sinon from 'sinon';
4+
import { setTimeout } from 'timers/promises';
35

6+
import { connect } from '../../mongodb';
47
import {
58
CONNECTION_POOL_CLEARED,
69
CONNECTION_POOL_READY,
710
type MongoClient,
811
SERVER_HEARTBEAT_FAILED,
12+
SERVER_HEARTBEAT_STARTED,
913
SERVER_HEARTBEAT_SUCCEEDED
1014
} from '../../mongodb';
1115

@@ -179,4 +183,40 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
179183
}
180184
});
181185
});
186+
187+
describe('Heartbeat tests', function () {
188+
let client: MongoClient;
189+
let connectSpy;
190+
const events: { event: any; time: number }[] = [];
191+
192+
// Spy on socket constructor
193+
194+
beforeEach(function () {
195+
client = this.configuration.newClient({
196+
heartbeatFrequencyMS: 10000,
197+
appName: 'HeartbeatTest',
198+
maxPoolSize: 1,
199+
minPoolSize: 0
200+
});
201+
202+
client.on(SERVER_HEARTBEAT_STARTED, event => {
203+
events.push({ event, time: performance.now() });
204+
});
205+
206+
// set up spy
207+
connectSpy = sinon.spy(connect);
208+
});
209+
210+
afterEach(async function () {
211+
sinon.restore();
212+
});
213+
214+
it('emits the first HeartbeatStartedEvent after the monitoring socket was created', async function () {
215+
await client.connect();
216+
await setTimeout(2000);
217+
await client.close();
218+
219+
expect(events).to.have.length.gte(2);
220+
});
221+
});
182222
});

0 commit comments

Comments
 (0)