Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(NODE-4157): SDAM unit test typescript and improvements #3182

Merged
merged 16 commits into from
Apr 8, 2022
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@types/saslprep": "^1.0.1",
"@types/semver": "^7.3.9",
"@types/sinon": "^10.0.11",
"@types/sinon-chai": "^3.2.8",
"@types/whatwg-url": "^8.2.1",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
Expand Down
1 change: 1 addition & 0 deletions src/sdam/topology_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export class TopologyDescription {
let { type: topologyType, setName, maxSetVersion, maxElectionId, commonWireVersion } = this;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "New primary",
"description": "Secondary ignored when ok is zero",
dariakp marked this conversation as resolved.
Show resolved Hide resolved
"uri": "mongodb://a,b/?replicaSet=rs",
"phases": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
description: "New primary"
description: "Secondary ignored when ok is zero"

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

Expand Down
8 changes: 4 additions & 4 deletions test/tools/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EJSON } from 'bson';
import { expect } from 'chai';
import * as util from 'util';
import { inspect, promisify } from 'util';

import { Logger } from '../../src/logger';
import { deprecateOptions, DeprecateOptionsConfig } from '../../src/utils';
Expand Down Expand Up @@ -182,15 +182,15 @@ export function shouldRunServerlessTest(testRequirement: any, isServerless: any)
* Attempts to use EJSON (to make type information obvious)
* falls back to util.inspect if there's an error (circular reference)
*/
export function ejson(strings: any[], ...values: any[]) {
export function ejson(strings: TemplateStringsArray, ...values: any[]) {
const stringParts = [strings[0]];
for (const [idx, value] of values.entries()) {
if (typeof value === 'object') {
let stringifiedObject: string;
try {
stringifiedObject = EJSON.stringify(value, { relaxed: false });
} catch (error) {
stringifiedObject = util.inspect(value, {
stringifiedObject = inspect(value, {
depth: Infinity,
showHidden: true,
compact: true
Expand All @@ -217,7 +217,7 @@ export const runLater = (fn: () => Promise<void>, ms: number) => {
});
};

export const sleep = util.promisify(setTimeout);
export const sleep = promisify(setTimeout);

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