-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(NODE-5228)!: remove unneeded fields from ConnectionPoolCreatedEvent.options #3772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f3438ea
fix(NODE-5228): fix ConnectionPoolCreatedEvent
W-A-James fb6e076
test(NODE-5228): make options required and add unit tests
W-A-James 5d34e01
chore(NODE-5228): rebuild lockfile
W-A-James 626a134
test(NODE-5228): update tests
W-A-James 0d3edad
test(NODE-5228): remove unneded test
W-A-James addbde5
test(NODE-5228): add type test
W-A-James File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.