Skip to content

Commit f4f9b46

Browse files
committed
revert prose test
1 parent 8e970e8 commit f4f9b46

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from 'chai';
2+
import { once } from 'events';
23
import { createServer, type Server } from 'net';
34

45
import { MongoClient, SERVER_HEARTBEAT_FAILED, SERVER_HEARTBEAT_STARTED } from '../../mongodb';
@@ -9,6 +10,8 @@ describe('Heartbeat tests', function () {
910
let server: Server;
1011
// Shared array
1112
const events: string[] = [];
13+
const PORT = 9999;
14+
const CONN_STRING = `mongodb://localhost:${PORT}`;
1215

1316
beforeEach(async function () {
1417
// Create TCP server that responds to hellos by closing the connection
@@ -18,21 +21,19 @@ describe('Heartbeat tests', function () {
1821

1922
clientSocket.once('data', () => {
2023
events.push('client hello received');
21-
clientSocket.end();
24+
clientSocket.destroy();
2225
});
2326
});
24-
server.listen(9999);
27+
server.listen(PORT);
28+
29+
await once(server, 'listening');
2530

2631
// set up client to connect to mock server with the following configuration
2732
// {
2833
// serverSelectionTimeoutMS: 500,
29-
// maxPoolSize: 1,
30-
// minPoolSize: 0
3134
// }
32-
client = new MongoClient('mongodb://localhost:9999', {
33-
serverSelectionTimeoutMS: 500,
34-
maxPoolSize: 1,
35-
minPoolSize: 0
35+
client = new MongoClient(CONN_STRING, {
36+
serverSelectionTimeoutMS: 500
3637
});
3738

3839
// Listen to `ServerHeartbeatStartedEvent` and `ServerHeartbeatSucceededEvent`, pushing the
@@ -42,22 +43,25 @@ describe('Heartbeat tests', function () {
4243
events.push(e);
4344
});
4445
}
45-
46-
// Attempt to connect to mock server
47-
const maybeError = await client.connect().catch(e => e);
48-
// Catch error
49-
expect(maybeError).to.be.instanceOf(Error);
5046
});
5147

5248
afterEach(async function () {
5349
if (server.listening) server.close();
5450
});
5551

56-
it('emits the first HeartbeatStartedEvent after the monitoring socket was created and before hello is sent', async function () {
52+
it('emits the first HeartbeatStartedEvent before the monitoring socket was created', async function () {
53+
// Attempt to connect to mock server
54+
const maybeError = await client.connect().catch(e => e);
55+
// Catch error
56+
expect(maybeError).to.be.instanceOf(Error);
57+
5758
expect(events).to.have.lengthOf(4);
58-
expect(events[0]).to.equal('client connection created');
59-
expect(events[1]).to.equal(SERVER_HEARTBEAT_STARTED);
60-
expect(events[2]).to.equal('client hello received');
61-
expect(events[3]).to.equal(SERVER_HEARTBEAT_FAILED);
59+
60+
expect(events).to.deep.equal([
61+
SERVER_HEARTBEAT_STARTED,
62+
'client connected',
63+
'client hello received',
64+
SERVER_HEARTBEAT_FAILED
65+
]);
6266
});
6367
});

0 commit comments

Comments
 (0)