Skip to content

Commit c01bf50

Browse files
committed
refactor: don't encode type name into public CMAP event types
1 parent 1aea4de commit c01bf50

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

lib/cmap/events.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
* @property {string} address The address (host/port pair) of the pool
88
*/
99
class ConnectionPoolMonitoringEvent {
10-
constructor(type, pool) {
10+
constructor(pool) {
1111
this.time = new Date();
12-
this.type = type;
1312
this.address = pool.address;
1413
}
1514
}
@@ -21,7 +20,7 @@ class ConnectionPoolMonitoringEvent {
2120
*/
2221
class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
2322
constructor(pool) {
24-
super('ConnectionPoolCreated', pool);
23+
super(pool);
2524
this.options = pool.options;
2625
}
2726
}
@@ -31,7 +30,7 @@ class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
3130
*/
3231
class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
3332
constructor(pool) {
34-
super('ConnectionPoolClosed', pool);
33+
super(pool);
3534
}
3635
}
3736

@@ -42,7 +41,7 @@ class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
4241
*/
4342
class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
4443
constructor(pool, connection) {
45-
super('ConnectionCreated', pool);
44+
super(pool);
4645
this.connectionId = connection.id;
4746
}
4847
}
@@ -54,7 +53,7 @@ class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
5453
*/
5554
class ConnectionReadyEvent extends ConnectionPoolMonitoringEvent {
5655
constructor(pool, connection) {
57-
super('ConnectionReady', pool);
56+
super(pool);
5857
this.connectionId = connection.id;
5958
}
6059
}
@@ -67,7 +66,7 @@ class ConnectionReadyEvent extends ConnectionPoolMonitoringEvent {
6766
*/
6867
class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent {
6968
constructor(pool, connection, reason) {
70-
super('ConnectionClosed', pool);
69+
super(pool);
7170
this.connectionId = connection.id;
7271
this.reason = reason || 'unknown';
7372
}
@@ -78,7 +77,7 @@ class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent {
7877
*/
7978
class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEvent {
8079
constructor(pool) {
81-
super('ConnectionCheckOutStarted', pool);
80+
super(pool);
8281
}
8382
}
8483

@@ -89,7 +88,7 @@ class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEvent {
8988
*/
9089
class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent {
9190
constructor(pool, reason) {
92-
super('ConnectionCheckOutFailed', pool);
91+
super(pool);
9392
this.reason = reason;
9493
}
9594
}
@@ -101,7 +100,7 @@ class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent {
101100
*/
102101
class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
103102
constructor(pool, connection) {
104-
super('ConnectionCheckedOut', pool);
103+
super(pool);
105104
this.connectionId = connection.id;
106105
}
107106
}
@@ -113,7 +112,7 @@ class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
113112
*/
114113
class ConnectionCheckedInEvent extends ConnectionPoolMonitoringEvent {
115114
constructor(pool, connection) {
116-
super('ConnectionCheckedIn', pool);
115+
super(pool);
117116
this.connectionId = connection.id;
118117
}
119118
}
@@ -123,7 +122,7 @@ class ConnectionCheckedInEvent extends ConnectionPoolMonitoringEvent {
123122
*/
124123
class ConnectionPoolClearedEvent extends ConnectionPoolMonitoringEvent {
125124
constructor(pool) {
126-
super('ConnectionPoolCleared', pool);
125+
super(pool);
127126
}
128127
}
129128

test/unit/cmap/connection_pool.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ describe('Connection Pool', function() {
438438
.then(() => mainThread.finish())
439439
.catch(e => (actualError = e))
440440
.then(() => {
441-
const actualEvents = poolEvents.filter(ev => ignoreEvents.indexOf(ev.type) < 0);
441+
const actualEvents = poolEvents.filter(ev => ignoreEvents.indexOf(eventType(ev)) < 0);
442442

443443
if (expectedError) {
444444
expect(actualError).to.exist;
@@ -451,6 +451,11 @@ describe('Connection Pool', function() {
451451

452452
expectedEvents.forEach((expected, index) => {
453453
const actual = actualEvents[index];
454+
if (expected.type) {
455+
expect(actual.constructor.name).to.equal(`${expected.type}Event`);
456+
delete expected.type;
457+
}
458+
454459
expect(actual).to.matchMongoSpec(expected);
455460
});
456461
});

0 commit comments

Comments
 (0)