Skip to content

Commit 920e72e

Browse files
added durations to checkOut events
1 parent a3c6eb9 commit 920e72e

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/cmap/connection.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
191191

192192
private lastUseTime: number;
193193
private clusterTime: Document | null = null;
194-
195194
private error: Error | null = null;
196195
private dataEvents: AsyncGenerator<Buffer, void, void> | null = null;
197196

@@ -230,7 +229,6 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
230229
this.description = new StreamDescription(this.address, options);
231230
this.generation = options.generation;
232231
this.lastUseTime = now();
233-
this.connectionCreatedEventTime = null;
234232

235233
this.messageStream = this.socket
236234
.on('error', this.onError.bind(this))

src/cmap/connection_pool.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
162162
[kWaitQueue]: List<WaitQueueMember>;
163163
[kMetrics]: ConnectionPoolMetrics;
164164
[kProcessingWaitQueue]: boolean;
165+
checkOutTime: undefined | number;
165166

166167
/**
167168
* Emitted when the connection pool is created.
@@ -355,6 +356,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
355356
* explicitly destroyed by the new owner.
356357
*/
357358
async checkOut(): Promise<Connection> {
359+
this.checkOutTime = Date.now();
358360
this.emitAndLog(
359361
ConnectionPool.CONNECTION_CHECK_OUT_STARTED,
360362
new ConnectionCheckOutStartedEvent(this)

src/cmap/connection_pool_events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent
229229
error?: MongoError
230230
) {
231231
super(pool);
232-
this.durationMS = this.durationMS = Date.now() - (connection.connectionCreatedEventTime ?? Date.now());
232+
this.durationMS = Date.now() - (pool.checkOutTime ?? 0);
233233
this.reason = reason;
234234
this.error = error;
235235
}
@@ -263,7 +263,7 @@ export class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
263263
/** @internal */
264264
constructor(pool: ConnectionPool, connection: Connection) {
265265
super(pool);
266-
this.durationMS = 0;
266+
this.durationMS = Date.now() - (pool.checkOutTime ?? 0);
267267
this.connectionId = connection.id;
268268
}
269269
}

test/integration/connection-monitoring-and-pooling/connection_monitoring_and_pooling.spec.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const INTERRUPT_IN_USE_SKIPPED_TESTS: SkipDescription[] = [
3939
}
4040
];
4141

42-
describe.only('Connection Monitoring and Pooling Spec Tests (Integration) - cmap-format', function () {
42+
describe('Connection Monitoring and Pooling Spec Tests (Integration) - cmap-format', function () {
4343
const tests: CmapTest[] = loadSpecTests('connection-monitoring-and-pooling', 'cmap-format');
4444

4545
runCmapTestSuite(tests, {
@@ -57,7 +57,7 @@ describe.only('Connection Monitoring and Pooling Spec Tests (Integration) - cmap
5757
});
5858
});
5959

60-
describe.only('Connection Monitoring and Pooling Spec Tests (Integration) - logging', function () {
60+
describe('Connection Monitoring and Pooling Spec Tests (Integration) - logging', function () {
6161
const tests = loadSpecTests('connection-monitoring-and-pooling', 'logging');
6262

6363
runUnifiedSuite(tests, test => {

0 commit comments

Comments
 (0)