Skip to content

Commit f9d4174

Browse files
Fixed operation names and remainingTimeMS function, altered replica-set spec test temporarily
1 parent e769798 commit f9d4174

File tree

9 files changed

+18
-12
lines changed

9 files changed

+18
-12
lines changed

src/change_stream.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,14 @@ export class ChangeStream<
934934
this.cursor.close().catch(() => null);
935935

936936
const topology = getTopology(this.parent);
937-
topology.selectServer(this.cursor.readPreference, {}, serverSelectionError => {
938-
if (serverSelectionError) return this._closeEmitterModeWithError(changeStreamError);
939-
this.cursor = this._createChangeStreamCursor(this.cursor.resumeOptions);
940-
});
937+
topology.selectServer(
938+
this.cursor.readPreference,
939+
{ operationName: 'reconnect topology' },
940+
serverSelectionError => {
941+
if (serverSelectionError) return this._closeEmitterModeWithError(changeStreamError);
942+
this.cursor = this._createChangeStreamCursor(this.cursor.resumeOptions);
943+
}
944+
);
941945
} else {
942946
this._closeEmitterModeWithError(changeStreamError);
943947
}
@@ -962,7 +966,9 @@ export class ChangeStream<
962966
await this.cursor.close().catch(() => null);
963967
const topology = getTopology(this.parent);
964968
try {
965-
await topology.selectServerAsync(this.cursor.readPreference, {});
969+
await topology.selectServerAsync(this.cursor.readPreference, {
970+
operationName: 'reconnect topology'
971+
});
966972
this.cursor = this._createChangeStreamCursor(this.cursor.resumeOptions);
967973
} catch {
968974
// if the topology can't reconnect, close the stream

src/sdam/server_selection_events.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
WAITING_FOR_SUITABLE_SERVER
66
} from '../constants';
77
import { type ReadPreference } from '../read_preference';
8-
import { HostAddress } from '../utils';
98
import { type ServerSelector } from './server_selection';
109
import type { TopologyDescription } from './topology_description';
1110

src/sdam/topology.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
455455
callback ? callback(error) : this.emit(Topology.ERROR, error);
456456

457457
const readPreference = options.readPreference ?? ReadPreference.primary;
458+
options = Object.assign({ operationName: 'ping' }, options);
458459
this.selectServer(readPreferenceServerSelector(readPreference), options, (err, server) => {
459460
if (err) {
460461
return this.close({ force: false }, () => exitWithError(err));

src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,8 +1290,9 @@ export class TimeoutController extends AbortController {
12901290
this.timeoutId = null;
12911291
}
12921292

1293+
/** May only be called for non-infinite timeouts */
12931294
getRemainingTimeMS() {
1294-
return Math.max(this.timeoutTimeMS - (Date.now() - this.startTime) / 1000, 0);
1295+
return Math.round(Math.max(this.timeoutTimeMS - (Date.now() - this.startTime) / 1000, 0));
12951296
}
12961297
}
12971298

test/integration/server-selection/server_selection.spec.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path';
33
import { loadSpecTests } from '../../spec';
44
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
55

6-
describe.only('Server Selection Tests - Unified', function () {
6+
describe('Server Selection Tests - Unified', function () {
77
const tests = loadSpecTests(path.join('server-selection', 'logging'));
88
runUnifiedSuite(tests, test => {
99
if (

test/spec/server-selection/logging/replica-set.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"collectionName": "unsatisfiableRPColl",
5353
"collectionOptions": {
5454
"readPreference": {
55-
"mode": "Secondary",
55+
"mode": "secondary",
5656
"tagSets": [
5757
{
5858
"nonexistenttag": "a"

test/spec/server-selection/logging/replica-set.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ createEntities:
3434
collectionName: &unsatisfiableRPColl unsatisfiableRPColl
3535
collectionOptions:
3636
readPreference:
37-
mode: Secondary
37+
mode: secondary
3838
tagSets:
3939
- { nonexistenttag : a }
4040

test/tools/unified-spec-runner/match.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,6 @@ export function compareLogs(
604604
actual: ExpectedLogMessage[],
605605
entities: EntitiesMap
606606
): void {
607-
608607
expect(actual).to.have.lengthOf(expected.length);
609608

610609
for (const [index, actualLog] of actual.entries()) {

test/tools/unified-spec-runner/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ async function runUnifiedTest(
237237
const filteredLogs = testClient!.collectedLogs.filter(
238238
log =>
239239
testClient!.mongoLogger.componentSeverities.serverSelection === 'off' ||
240-
log?.data?.operation !== 'n/a'
240+
(log?.data?.operation !== 'reconnect topology' && log?.data?.operation !== 'ping')
241241
);
242242
compareLogs(expectedLogsForClient.messages, filteredLogs, entities);
243243
}

0 commit comments

Comments
 (0)