-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(NODE-3697): reduce serverSession allocation #3171
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
dariakp
merged 14 commits into
main
from
NODE-3697/implicit-session-acquire-after-checkout
Mar 25, 2022
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8f7c72a
feat(NODE-3697): reduce serverSession allocation
nbbeeken 6bf7b53
wip
nbbeeken 02464c8
fix: hasEnded logic and test
nbbeeken a417d00
some comments
nbbeeken 522408b
reorganize unit tests and add hasEnded false test
nbbeeken ef98aee
test and throw updates
nbbeeken fefdfa2
merge boolean checks
nbbeeken cbadd92
reorganized serverSession getter tests
nbbeeken 34a2ee4
test: scenario where explicit session is separated from its server se…
nbbeeken b53255c
Boolean Logic++
nbbeeken c8b1057
Apply suggestions from code review
nbbeeken 5a22be4
test: add check for acquire not being called again
nbbeeken fc37a3e
test: ended implict session doesn't call acquire
nbbeeken 3570ed6
make sure session id doesn't change
nbbeeken 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
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
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
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
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,51 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { Collection } from '../../../src/index'; | ||
|
||
describe('ServerSession', () => { | ||
let client; | ||
let testCollection: Collection<{ _id: number; a?: number }>; | ||
beforeEach(async function () { | ||
const configuration = this.configuration; | ||
client = await configuration.newClient({ maxPoolSize: 1, monitorCommands: true }).connect(); | ||
|
||
// reset test collection | ||
testCollection = client.db('test').collection('too.many.sessions'); | ||
await testCollection.drop().catch(() => null); | ||
}); | ||
|
||
afterEach(async () => { | ||
await client?.close(true); | ||
}); | ||
|
||
/** | ||
* TODO(NODE-4082): Refactor tests to align exactly with spec wording. | ||
* Assert the following across at least 5 retries of the above test: (We do not need to retry in nodejs) | ||
* Drivers MUST assert that exactly one session is used for all operations at least once across the retries of this test. | ||
* Note that it's possible, although rare, for greater than 1 server session to be used because the session is not released until after the connection is checked in. | ||
* Drivers MUST assert that the number of allocated sessions is strictly less than the number of concurrent operations in every retry of this test. In this instance it would less than (but NOT equal to) 8. | ||
*/ | ||
it('13. may reuse one server session for many operations', async () => { | ||
const events = []; | ||
client.on('commandStarted', ev => events.push(ev)); | ||
|
||
const operations = [ | ||
nbbeeken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
testCollection.insertOne({ _id: 1 }), | ||
testCollection.deleteOne({ _id: 2 }), | ||
testCollection.updateOne({ _id: 3 }, { $set: { a: 1 } }), | ||
testCollection.bulkWrite([{ updateOne: { filter: { _id: 4 }, update: { $set: { a: 1 } } } }]), | ||
testCollection.findOneAndDelete({ _id: 5 }), | ||
testCollection.findOneAndUpdate({ _id: 6 }, { $set: { a: 1 } }), | ||
testCollection.findOneAndReplace({ _id: 7 }, { a: 8 }), | ||
testCollection.find().toArray() | ||
]; | ||
|
||
const allResults = await Promise.all(operations); | ||
|
||
expect(allResults).to.have.lengthOf(operations.length); | ||
expect(events).to.have.lengthOf(operations.length); | ||
|
||
// This is a guarantee in node, unless you are performing a transaction (which is not being done in this test) | ||
expect(new Set(events.map(ev => ev.command.lsid.id.toString('hex'))).size).to.equal(1); | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.
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.