Skip to content

Commit 76c98bb

Browse files
authored
test(NODE-5206): fix flaky sdam prose test (#4752)
1 parent cb522bf commit 76c98bb

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,15 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
110110
*/
111111

112112
let client: MongoClient;
113+
let utilClient: MongoClient;
113114
const events: string[] = [];
114115
beforeEach(async function () {
115116
client = this.configuration.newClient({
116117
directConnection: true,
117118
appName: 'SDAMPoolManagementTest',
118-
heartbeatFrequencyMS: 500
119+
heartbeatFrequencyMS: 100
119120
});
121+
utilClient = this.configuration.newClient({ directConnection: true });
120122

121123
for (const event of [
122124
CONNECTION_POOL_READY,
@@ -144,6 +146,7 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
144146

145147
afterEach(async function () {
146148
await client.close();
149+
await utilClient.close();
147150
});
148151

149152
it('ensure monitors properly create and unpause connection pools when they discover servers', {
@@ -156,7 +159,7 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
156159
expect(events).to.be.empty;
157160

158161
const heartBeatFailedEvent = once(client, SERVER_HEARTBEAT_FAILED);
159-
await client.db('admin').command({
162+
await utilClient.db('admin').command({
160163
configureFailPoint: 'failCommand',
161164
mode: { times: 2 },
162165
data: {
@@ -165,17 +168,22 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
165168
appName: 'SDAMPoolManagementTest'
166169
}
167170
});
171+
168172
await heartBeatFailedEvent;
169173
expect(events.shift()).to.equal(SERVER_HEARTBEAT_FAILED);
170174
expect(events.shift()).to.equal(CONNECTION_POOL_CLEARED);
171175

172176
expect(events).to.be.empty;
173177

174178
await once(client, SERVER_HEARTBEAT_SUCCEEDED);
175-
expect(events.shift()).to.equal(SERVER_HEARTBEAT_SUCCEEDED);
176-
expect(events.shift()).to.equal(CONNECTION_POOL_READY);
177-
178-
expect(events).to.be.empty;
179+
// In rare cases when using the stable API, an extra server heartbeat failed event may sneak in.
180+
// The test just needs to assert that at some point we have another server heartbeat suceeded
181+
// event followed by a connection pool ready event.
182+
const filteredEvents = events.filter(event => event !== SERVER_HEARTBEAT_FAILED);
183+
expect(filteredEvents.shift()).to.equal(SERVER_HEARTBEAT_SUCCEEDED);
184+
expect(filteredEvents.shift()).to.equal(CONNECTION_POOL_READY);
185+
186+
expect(filteredEvents).to.be.empty;
179187
}
180188
});
181189
});

0 commit comments

Comments
 (0)