Skip to content

Commit ba2aa44

Browse files
committed
test(NODE-5206): fix flaky sdam prose test
1 parent e1ea14c commit ba2aa44

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

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

Lines changed: 15 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,
@@ -125,6 +127,7 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
125127
CONNECTION_POOL_CLEARED
126128
]) {
127129
client.on(event, () => {
130+
console.log(event);
128131
events.push(event);
129132
});
130133
}
@@ -144,6 +147,7 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
144147

145148
afterEach(async function () {
146149
await client.close();
150+
await utilClient.close();
147151
});
148152

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

158162
const heartBeatFailedEvent = once(client, SERVER_HEARTBEAT_FAILED);
159-
await client.db('admin').command({
163+
await utilClient.db('admin').command({
160164
configureFailPoint: 'failCommand',
161165
mode: { times: 2 },
162166
data: {
@@ -165,17 +169,22 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
165169
appName: 'SDAMPoolManagementTest'
166170
}
167171
});
172+
168173
await heartBeatFailedEvent;
169174
expect(events.shift()).to.equal(SERVER_HEARTBEAT_FAILED);
170175
expect(events.shift()).to.equal(CONNECTION_POOL_CLEARED);
171176

172177
expect(events).to.be.empty;
173178

174179
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;
180+
// In rare cases when using the stable API, an extra server heartbeat failed event may sneak in.
181+
// The test just needs to assert that at some point we have another server heartbeat suceeded
182+
// event followed by a connection pool ready event.
183+
const filteredEvents = events.filter(event => event !== SERVER_HEARTBEAT_FAILED);
184+
expect(filteredEvents.shift()).to.equal(SERVER_HEARTBEAT_SUCCEEDED);
185+
expect(filteredEvents.shift()).to.equal(CONNECTION_POOL_READY);
186+
187+
expect(filteredEvents).to.be.empty;
179188
}
180189
});
181190
});

0 commit comments

Comments
 (0)