Skip to content

Commit b8b5173

Browse files
committed
test(NODE-5197): move started event
1 parent dd81180 commit b8b5173

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

src/sdam/monitor.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export class Monitor extends TypedEventEmitter<MonitorEvents> {
120120
minHeartbeatFrequencyMS: options.minHeartbeatFrequencyMS ?? 500,
121121
serverMonitoringMode: options.serverMonitoringMode
122122
});
123-
console.log(getFAASEnv());
124123
this.isRunningInFaasEnv = getFAASEnv() != null;
125124

126125
const cancellationToken = this[kCancellationToken];
@@ -242,25 +241,19 @@ function useStreamingProtocol(monitor: Monitor, topologyVersion: TopologyVersion
242241
function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
243242
let start = now();
244243
const topologyVersion = monitor[kServer].description.topologyVersion;
245-
console.log('checkServer', topologyVersion);
246244
const isAwaitable = useStreamingProtocol(monitor, topologyVersion);
247245
monitor.emit(
248246
Server.SERVER_HEARTBEAT_STARTED,
249247
new ServerHeartbeatStartedEvent(monitor.address, isAwaitable)
250248
);
251249

252-
function failureHandler(err: Error) {
250+
function failureHandler(err: Error, awaited: boolean) {
253251
monitor[kConnection]?.destroy({ force: true });
254252
monitor[kConnection] = undefined;
255253

256254
monitor.emit(
257255
Server.SERVER_HEARTBEAT_FAILED,
258-
new ServerHeartbeatFailedEvent(
259-
monitor.address,
260-
calculateDurationInMs(start),
261-
err,
262-
isAwaitable
263-
)
256+
new ServerHeartbeatFailedEvent(monitor.address, calculateDurationInMs(start), err, awaited)
264257
);
265258

266259
const error = !(err instanceof MongoError)
@@ -307,7 +300,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
307300

308301
connection.command(ns('admin.$cmd'), cmd, options, (err, hello) => {
309302
if (err) {
310-
return failureHandler(err);
303+
return failureHandler(err, isAwaitable);
311304
}
312305

313306
if (!('isWritablePrimary' in hello)) {
@@ -319,16 +312,12 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
319312
const duration =
320313
isAwaitable && rttPinger ? rttPinger.roundTripTime : calculateDurationInMs(start);
321314

322-
console.log('command', topologyVersion, hello.topologyVersion, hello);
323-
const awaited = useStreamingProtocol(monitor, hello.topologyVersion);
324315
monitor.emit(
325316
Server.SERVER_HEARTBEAT_SUCCEEDED,
326-
new ServerHeartbeatSucceededEvent(monitor.address, duration, hello, awaited)
317+
new ServerHeartbeatSucceededEvent(monitor.address, duration, hello, isAwaitable)
327318
);
328319

329-
// if we are using the streaming protocol then we immediately issue another `started`
330-
// event, otherwise the "check" is complete and return to the main monitor loop
331-
if (awaited) {
320+
if (isAwaitable) {
332321
monitor.emit(
333322
Server.SERVER_HEARTBEAT_STARTED,
334323
new ServerHeartbeatStartedEvent(monitor.address, true)
@@ -350,7 +339,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
350339
if (err) {
351340
monitor[kConnection] = undefined;
352341

353-
failureHandler(err);
342+
failureHandler(err, false);
354343
return;
355344
}
356345

@@ -371,7 +360,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
371360
monitor.address,
372361
calculateDurationInMs(start),
373362
conn.hello,
374-
false
363+
useStreamingProtocol(monitor, conn.hello?.topologyVersion)
375364
)
376365
);
377366

@@ -404,7 +393,6 @@ function monitorServer(monitor: Monitor) {
404393
}
405394

406395
// if the check indicates streaming is supported, immediately reschedule monitoring
407-
console.log('checkServerCallback', hello?.topologyVersion);
408396
if (useStreamingProtocol(monitor, hello?.topologyVersion)) {
409397
setTimeout(() => {
410398
if (!isInCloseState(monitor)) {

test/integration/change-streams/change_stream.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ describe('Change Streams', function () {
18231823
});
18241824
});
18251825

1826-
describe.only('ChangeStream resumability', function () {
1826+
describe('ChangeStream resumability', function () {
18271827
let client: MongoClient;
18281828
let collection: Collection;
18291829
let changeStream: ChangeStream;

0 commit comments

Comments
 (0)