-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(NODE-5228)!: remove unneeded fields from ConnectionPoolCreatedEve…
…nt.options (#3772)
- Loading branch information
Showing
5 changed files
with
155 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
test/integration/connection-monitoring-and-pooling/connection_pool.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { once } from 'node:events'; | ||
|
||
import { expect } from 'chai'; | ||
|
||
import { type ConnectionPoolCreatedEvent, type Db, type MongoClient } from '../../mongodb'; | ||
|
||
describe('Connection Pool', function () { | ||
let client: MongoClient; | ||
let db: Db; | ||
afterEach(async function () { | ||
if (client) { | ||
if (db) { | ||
await db.dropDatabase(); | ||
} | ||
await client.close(); | ||
} | ||
}); | ||
describe('Events', function () { | ||
describe('ConnectionPoolCreatedEvent', function () { | ||
context('when no connection pool options are passed in', function () { | ||
let pConnectionPoolCreated: Promise<ConnectionPoolCreatedEvent[]>; | ||
let connectionPoolCreated: ConnectionPoolCreatedEvent; | ||
beforeEach(async function () { | ||
client = this.configuration.newClient({}, {}); | ||
pConnectionPoolCreated = once(client, 'connectionPoolCreated'); | ||
await client.connect(); | ||
|
||
connectionPoolCreated = (await pConnectionPoolCreated)[0]; | ||
}); | ||
|
||
it('the options field matches the default options', function () { | ||
expect(connectionPoolCreated).to.have.deep.property('options', { | ||
waitQueueTimeoutMS: 0, | ||
maxIdleTimeMS: 0, | ||
maxConnecting: 2, | ||
minPoolSize: 0, | ||
maxPoolSize: 100 | ||
}); | ||
}); | ||
}); | ||
|
||
context('when valid non-default connection pool options are passed in', function () { | ||
let pConnectionPoolCreated: Promise<ConnectionPoolCreatedEvent[]>; | ||
let connectionPoolCreated: ConnectionPoolCreatedEvent; | ||
const options = { | ||
waitQueueTimeoutMS: 2000, | ||
maxIdleTimeMS: 1, | ||
maxConnecting: 3, | ||
minPoolSize: 1, | ||
maxPoolSize: 101 | ||
}; | ||
beforeEach(async function () { | ||
client = this.configuration.newClient({}, options); | ||
pConnectionPoolCreated = once(client, 'connectionPoolCreated'); | ||
await client.connect(); | ||
|
||
connectionPoolCreated = (await pConnectionPoolCreated)[0]; | ||
}); | ||
|
||
it('the options field only contains keys and values matching the non-default options', function () { | ||
expect(connectionPoolCreated).to.have.deep.property('options', options); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { once } from 'events'; | ||
import { expectType } from 'tsd'; | ||
|
||
import type { ConnectionPoolCreatedEvent } from '../mongodb'; | ||
import { MongoClient } from '../mongodb'; | ||
|
||
const client: MongoClient = new MongoClient(''); | ||
const p = once(client, 'connectionPoolCreated'); | ||
await client.connect(); | ||
|
||
const ev: ConnectionPoolCreatedEvent = (await p)[0]; | ||
expectType<ConnectionPoolCreatedEvent>(ev); | ||
|
||
expectType<{ | ||
maxPoolSize: number; | ||
minPoolSize: number; | ||
maxConnecting: number; | ||
maxIdleTimeMS: number; | ||
waitQueueTimeoutMS: number; | ||
}>(ev.options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { type ConnectionPool, ConnectionPoolCreatedEvent } from '../../mongodb'; | ||
|
||
describe('Connection Pool Events', function () { | ||
const connectionPoolMock = { | ||
address: 'localhost:9000', | ||
time: new Date() | ||
}; | ||
|
||
describe('ConnectionPoolCreatedEvent', function () { | ||
describe('constructor', function () { | ||
context('when provided expected option fields', function () { | ||
it(`Sets the allowed fields appropriately`, function () { | ||
const options = { | ||
maxIdleTimeMS: 0, | ||
maxConnecting: 2, | ||
minPoolSize: 0, | ||
maxPoolSize: 100, | ||
waitQueueTimeoutMS: 1000 | ||
}; | ||
const event = new ConnectionPoolCreatedEvent({ | ||
...connectionPoolMock, | ||
options | ||
} as unknown as ConnectionPool); | ||
|
||
expect(event).to.have.deep.property('options', options); | ||
}); | ||
}); | ||
context('when provided unallowed fields', function () { | ||
it('only stores expected fields', function () { | ||
const options = { | ||
maxIdleTimeMS: 0, | ||
maxConnecting: 2, | ||
minPoolSize: 0, | ||
maxPoolSize: 100, | ||
waitQueueTimeoutMS: 1000, | ||
credentials: { | ||
user: 'user', | ||
pass: 'pass' | ||
}, | ||
foo: 'foo', | ||
hello: 'world' | ||
}; | ||
const event = new ConnectionPoolCreatedEvent({ | ||
...connectionPoolMock, | ||
options | ||
} as unknown as ConnectionPool); | ||
|
||
expect(event).to.have.deep.property('options', { | ||
maxIdleTimeMS: 0, | ||
maxConnecting: 2, | ||
minPoolSize: 0, | ||
maxPoolSize: 100, | ||
waitQueueTimeoutMS: 1000 | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |