Skip to content

Commit 39120a6

Browse files
committed
refactor(NODE-5170): update unified spec test runner
1 parent d502eb0 commit 39120a6

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

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

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
22
import { expect } from 'chai';
33
import { EventEmitter } from 'events';
4-
import { Writable } from 'stream';
54

65
import {
76
AbstractCursor,
@@ -26,6 +25,7 @@ import {
2625
Document,
2726
GridFSBucket,
2827
HostAddress,
28+
Log,
2929
MongoClient,
3030
MongoCredentials,
3131
ReadConcern,
@@ -107,33 +107,12 @@ function getClient(address) {
107107
return new MongoClient(`mongodb://${address}`, getEnvironmentalOptions());
108108
}
109109

110-
// TODO(NODE-4813): Remove this class in favour of a simple object with a write method
111-
/* TODO(NODE-4813): Ensure that the object that we replace this with has logic to convert the
112-
* collected log into the format require by the unified spec runner
113-
* (see ExpectedLogMessage type in schema.ts) */
114-
export class UnifiedLogCollector extends Writable {
115-
collectedLogs: LogMessage[] = [];
116-
117-
constructor() {
118-
super({ objectMode: true });
119-
}
120-
121-
_write(
122-
log: LogMessage,
123-
_: string,
124-
callback: (e: Error | null, l: LogMessage | undefined) => void
125-
) {
126-
this.collectedLogs.push(log);
127-
callback(null, log);
128-
}
129-
}
130-
131110
export class UnifiedMongoClient extends MongoClient {
132111
commandEvents: CommandEvent[] = [];
133112
cmapEvents: CmapEvent[] = [];
134113
sdamEvents: SdamEvent[] = [];
135114
failPoints: Document[] = [];
136-
logCollector: UnifiedLogCollector;
115+
logCollector: { buffer: LogMessage[]; write: (log: Log) => void };
137116

138117
ignoredEvents: string[];
139118
observedCommandEvents: ('commandStarted' | 'commandSucceeded' | 'commandFailed')[];
@@ -186,7 +165,18 @@ export class UnifiedMongoClient extends MongoClient {
186165
} as const;
187166

188167
constructor(uri: string, description: ClientEntity) {
189-
const logCollector = new UnifiedLogCollector();
168+
const logCollector: { buffer: LogMessage[]; write: (log: Log) => void } = {
169+
buffer: [],
170+
write(log: Log): void {
171+
const transformedLog = {
172+
level: log.s,
173+
component: log.c,
174+
data: { ...log, s: undefined, c: undefined }
175+
};
176+
177+
this.buffer.push(transformedLog);
178+
}
179+
};
190180
const componentSeverities = {
191181
MONGODB_LOG_ALL: 'off'
192182
};
@@ -205,7 +195,7 @@ export class UnifiedMongoClient extends MongoClient {
205195
mongodbLogPath: logCollector,
206196
...getEnvironmentalOptions(),
207197
...(description.serverApi ? { serverApi: description.serverApi } : {})
208-
});
198+
} as any);
209199
this.logCollector = logCollector;
210200

211201
this.ignoredEvents = [
@@ -296,7 +286,7 @@ export class UnifiedMongoClient extends MongoClient {
296286
}
297287

298288
get collectedLogs(): LogMessage[] {
299-
return this.logCollector.collectedLogs;
289+
return this.logCollector.buffer;
300290
}
301291
}
302292

0 commit comments

Comments
 (0)