Skip to content

Commit 68ffd88

Browse files
PR requested changes 4
1 parent d785677 commit 68ffd88

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

src/mongo_logger.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export function createStdioLogger(stream: {
219219
write: NodeJS.WriteStream['write'];
220220
}): MongoDBLogWritable {
221221
return {
222-
write: promisify((log: Log, cb: () => void): unknown => {
222+
write: promisify((log: Log, cb: (error?: Error) => void): unknown => {
223223
stream.write(inspect(log, { compact: true, breakLength: Infinity }), 'utf-8', cb);
224224
return;
225225
})
@@ -418,10 +418,7 @@ export function stringifyWithMaxLen(
418418
let strToTruncate = '';
419419

420420
try {
421-
strToTruncate =
422-
typeof value !== 'function'
423-
? EJSON.stringify(value, options)
424-
: 'ReadPreference function';
421+
strToTruncate = typeof value !== 'function' ? EJSON.stringify(value, options) : value.name;
425422
} catch (e) {
426423
strToTruncate = `Extended JSON serialization failed with: ${e.message}`;
427424
}

src/sdam/server_selection.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,26 @@ export type ServerSelector = (
2222
* Returns a server selector that selects for writable servers
2323
*/
2424
export function writableServerSelector(): ServerSelector {
25-
return (
25+
return function writableServer(
2626
topologyDescription: TopologyDescription,
2727
servers: ServerDescription[]
28-
): ServerDescription[] =>
29-
latencyWindowReducer(
28+
): ServerDescription[] {
29+
return latencyWindowReducer(
3030
topologyDescription,
3131
servers.filter((s: ServerDescription) => s.isWritable)
3232
);
33+
};
3334
}
3435

3536
/**
3637
* The purpose of this selector is to select the same server, only
3738
* if it is in a state that it can have commands sent to it.
3839
*/
3940
export function sameServerSelector(description?: ServerDescription): ServerSelector {
40-
return (
41+
return function sameServerSelector(
4142
topologyDescription: TopologyDescription,
4243
servers: ServerDescription[]
43-
): ServerDescription[] => {
44+
): ServerDescription[] {
4445
if (!description) return [];
4546
// Filter the servers to match the provided description only if
4647
// the type is not unknown.
@@ -265,11 +266,11 @@ export function readPreferenceServerSelector(readPreference: ReadPreference): Se
265266
throw new MongoInvalidArgumentError('Invalid read preference specified');
266267
}
267268

268-
return (
269+
return function readPreferenceServers(
269270
topologyDescription: TopologyDescription,
270271
servers: ServerDescription[],
271272
deprioritized: ServerDescription[] = []
272-
): ServerDescription[] => {
273+
): ServerDescription[] {
273274
const commonWireVersion = topologyDescription.commonWireVersion;
274275
if (
275276
commonWireVersion &&

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export function applyRetryableWrites<T extends HasRetryableWrites>(target: T, db
171171
* @param value - An object that could be a promise
172172
* @returns true if the provided value is a Promise
173173
*/
174-
export function isPromiseLike<T = any>(value?: unknown): value is Promise<T> {
174+
export function isPromiseLike<T = any>(value?: unknown): value is PromiseLike<T> {
175175
return (
176176
value != null &&
177177
typeof value === 'object' &&

test/unit/mongo_logger.test.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('meta tests for BufferingStream', function () {
5656
});
5757
});
5858

59-
describe.only('class MongoLogger', async function () {
59+
describe('class MongoLogger', async function () {
6060
describe('#constructor()', function () {
6161
it('assigns each property from the options object onto the logging class', function () {
6262
const componentSeverities: MongoLoggerOptions['componentSeverities'] = {
@@ -1315,32 +1315,39 @@ describe.only('class MongoLogger', async function () {
13151315
for (const errorInput of errorInputs) {
13161316
context(`when value is ${errorInput.name}`, function () {
13171317
it('should output default error message, with no error thrown', function () {
1318-
expect(stringifyWithMaxLen(errorInput.input, 25)).to.equal(
1319-
'... ESJON failed : Error ...'
1318+
expect(stringifyWithMaxLen(errorInput.input, 40)).to.equal(
1319+
'Extended JSON serialization failed with:...'
13201320
);
13211321
});
13221322
});
13231323
}
13241324
});
13251325

1326-
context('when given anonymous function as input', function () {
1327-
it('should output default error message', function () {
1328-
expect(stringifyWithMaxLen((v: number) => v + 1, DEFAULT_MAX_DOCUMENT_LENGTH)).to.equal(
1329-
'anonymous function'
1330-
);
1326+
context('when given function as input', function () {
1327+
it('should output function.name', function () {
1328+
expect(
1329+
stringifyWithMaxLen(function randomFunc() {
1330+
return 1;
1331+
}, DEFAULT_MAX_DOCUMENT_LENGTH)
1332+
).to.equal('randomFunc');
13311333
});
13321334
});
13331335
});
13341336
});
13351337

13361338
describe('log', async function () {
1337-
const componentSeverities: MongoLoggerOptions['componentSeverities'] = {
1338-
command: 'trace',
1339-
topology: 'trace',
1340-
serverSelection: 'trace',
1341-
connection: 'trace',
1342-
client: 'trace'
1343-
} as any;
1339+
let componentSeverities: MongoLoggerOptions['componentSeverities'];
1340+
1341+
beforeEach(function () {
1342+
componentSeverities = {
1343+
command: 'trace',
1344+
topology: 'trace',
1345+
serverSelection: 'trace',
1346+
connection: 'trace',
1347+
client: 'trace'
1348+
} as any;
1349+
});
1350+
13441351
describe('sync stream failure handling', function () {
13451352
context('when stream is not stderr', function () {
13461353
let stderrStub;

0 commit comments

Comments
 (0)