-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(NODE-6390): Add timeoutMS support to auto encryption #4265
Conversation
Co-authored-by: Warren James <[email protected]>
Co-authored-by: Warren James <[email protected]>
lint fix prose test 2
Co-authored-by: Warren James <[email protected]>
d224fff
to
c3f31da
Compare
c3f31da
to
4fd4b24
Compare
const metadata: MongoDBMetadataUI = { | ||
requires: { | ||
mongodb: '>=4.2.0', | ||
clientSideEncryption: '>=6.1.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clientSideEncryption: '>=6.1.0' |
mongodb-client-encryption 6.1.0 shouldn't be required for these tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few small comments!
}); | ||
}); | ||
|
||
context('when client is not provided timeoutMS and command hangs', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context('when client is not provided timeoutMS and command hangs', function () { | |
context('when client is not provided timeoutMS and auto encryption is delayed', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the change! - editted to match the test name at line 545 since they test the same scenario - just with and without timeoutMS
}); | ||
|
||
it( | ||
'the command should not fail due to a server error', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'the command should not fail due to a server error', | |
'the command succeeds', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
client = new MongoClient(`mongodb://localhost:${mongocryptdTestPort}/?timeoutMS=1000`, { | ||
monitorCommands: true | ||
family: 6, | ||
monitorCommands: true, | ||
serverSelectionTimeoutMS: 2000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like they're still there
}; | ||
|
||
context('when client is provided timeoutMS and command hangs', function () { | ||
let encryptedClient: MongoClient; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make the test titles more precise? command hangs
is a bit vague - specifically we're concerned with autoEncryption timing out so the test should make that clear.
let encryptedClient: MongoClient; | |
context('when an auto encrypted client is configured with timeoutMS and autoEncryption takes longer than timeoutMS', function () { | |
it('the command times out', function() {} ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I can make the title more specific!
}); | ||
|
||
afterEach(async function () { | ||
encryptedClient.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encryptedClient.close(); | |
await encryptedClient.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, my bad!
}; | ||
|
||
describe('#markCommand', function () { | ||
context('when provided timeoutContext and command hangs', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context('when provided timeoutContext and command hangs', function () { | |
context('when csot is enabled and markCommand() takes longer than the remaining timeoutMS', function() { |
we always provide a timeoutContext to markCommand()
(and other state machine helper functions that we test here, so this comment is relevant for listCollections and getKeys). also, let's be precise with the exact scenario we're testing here - that the command fails if it takes longer than the remaining timeoutMS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure i can change it. my original thinking is that timeoutContext is only registered when it's non-nullish but ig also in the case that the timeoutContext is non-csot.
const err = await encryptedClient | ||
.db('test') | ||
.collection('test') | ||
.insertOne({ a: 1 }) | ||
.catch(e => e); | ||
expect(err).to.be.instanceOf(MongoOperationTimeoutError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We realized last week that it is important to measure the duration of the command when we expect it to time out. If we expect it to time out in timeoutMS, then we need to confirm it actually took no more than timeoutMS to complete.
There's some flexibility here, because CSOT isn't a hard gaurantee, but in other tests we've measured the duration (there's a measureDuration helper) and we assert its within a range of timeoutMS
. Can we do the same here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies to other places we're testing CSOT too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added it in to all 5 csot enabled testing cases from this PR
await setupClient.close(); | ||
}); | ||
|
||
context('when provided timeoutContext and command hangs', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as markCommand's describe block
Co-authored-by: Warren James <[email protected]> Co-authored-by: Neal Beeken <[email protected]> Co-authored-by: Bailey Pearson <[email protected]>
Co-authored-by: Warren James <[email protected]> Co-authored-by: Neal Beeken <[email protected]> Co-authored-by: Bailey Pearson <[email protected]>
Co-authored-by: Warren James <[email protected]> Co-authored-by: Neal Beeken <[email protected]> Co-authored-by: Bailey Pearson <[email protected]>
Description
Auto encryption
encrypt
anddecrypt
helpers now respecttimeoutMS
.What is changing?
timeoutContext
tostateMachine.execute
call inAutoEncrypter.encrypt/decrypt
StateMachine
helpers respectingtimeoutMS
CryptoConnection.command
respecting timeoutMSIs there new documentation needed for these changes?
No
What is the motivation for this change?
CSOT
Double check the following
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript