Skip to content

Commit 7bffb7b

Browse files
authored
test(NODE-4157): SDAM unit test typescript and improvements (#3182)
1 parent 513a88b commit 7bffb7b

File tree

8 files changed

+559
-391
lines changed

8 files changed

+559
-391
lines changed

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@types/saslprep": "^1.0.1",
4545
"@types/semver": "^7.3.9",
4646
"@types/sinon": "^10.0.11",
47+
"@types/sinon-chai": "^3.2.8",
4748
"@types/whatwg-url": "^8.2.1",
4849
"@typescript-eslint/eslint-plugin": "^5.17.0",
4950
"@typescript-eslint/parser": "^5.17.0",

src/sdam/topology_description.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ export class TopologyDescription {
201201
let { type: topologyType, setName, maxSetVersion, maxElectionId, commonWireVersion } = this;
202202

203203
if (serverDescription.setName && setName && serverDescription.setName !== setName) {
204+
// TODO(NODE-4159): servers with an incorrect setName should be removed not marked Unknown
204205
serverDescription = new ServerDescription(address, undefined);
205206
}
206207

test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "New primary",
2+
"description": "Secondary ignored when ok is zero",
33
"uri": "mongodb://a,b/?replicaSet=rs",
44
"phases": [
55
{

test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
description: "New primary"
1+
description: "Secondary ignored when ok is zero"
22

33
uri: "mongodb://a,b/?replicaSet=rs"
44

test/tools/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EJSON } from 'bson';
22
import { expect } from 'chai';
3-
import * as util from 'util';
3+
import { inspect, promisify } from 'util';
44

55
import { Logger } from '../../src/logger';
66
import { deprecateOptions, DeprecateOptionsConfig } from '../../src/utils';
@@ -182,15 +182,15 @@ export function shouldRunServerlessTest(testRequirement: any, isServerless: any)
182182
* Attempts to use EJSON (to make type information obvious)
183183
* falls back to util.inspect if there's an error (circular reference)
184184
*/
185-
export function ejson(strings: any[], ...values: any[]) {
185+
export function ejson(strings: TemplateStringsArray, ...values: any[]) {
186186
const stringParts = [strings[0]];
187187
for (const [idx, value] of values.entries()) {
188188
if (typeof value === 'object') {
189189
let stringifiedObject: string;
190190
try {
191191
stringifiedObject = EJSON.stringify(value, { relaxed: false });
192192
} catch (error) {
193-
stringifiedObject = util.inspect(value, {
193+
stringifiedObject = inspect(value, {
194194
depth: Infinity,
195195
showHidden: true,
196196
compact: true
@@ -217,7 +217,7 @@ export const runLater = (fn: () => Promise<void>, ms: number) => {
217217
});
218218
};
219219

220-
export const sleep = util.promisify(setTimeout);
220+
export const sleep = promisify(setTimeout);
221221

222222
/**
223223
* If you are using sinon fake timers, it can end up blocking queued IO from running

0 commit comments

Comments
 (0)