Skip to content
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

Merged
merged 150 commits into from
Oct 25, 2024

Conversation

aditi-khare-mongoDB
Copy link
Contributor

@aditi-khare-mongoDB aditi-khare-mongoDB commented Oct 2, 2024

Description

Auto encryption encrypt and decrypt helpers now respect timeoutMS.

What is changing?

  • Added timeoutContext to stateMachine.execute call in AutoEncrypter.encrypt/decrypt
  • Integration tests for StateMachine helpers respecting timeoutMS
  • Integration tests for CryptoConnection.command respecting timeoutMS
  • Spec unit test for Auto Encryption
Is there new documentation needed for these changes?

No

What is the motivation for this change?

CSOT

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

W-A-James and others added 30 commits September 12, 2024 13:43
lint

fix

prose test 2
const metadata: MongoDBMetadataUI = {
requires: {
mongodb: '>=4.2.0',
clientSideEncryption: '>=6.1.0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
clientSideEncryption: '>=6.1.0'

mongodb-client-encryption 6.1.0 shouldn't be required for these tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it!

Copy link
Contributor

@baileympearson baileympearson left a 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 () {
Copy link
Contributor

@baileympearson baileympearson Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
context('when client is not provided timeoutMS and command hangs', function () {
context('when client is not provided timeoutMS and auto encryption is delayed', function () {

Copy link
Contributor Author

@aditi-khare-mongoDB aditi-khare-mongoDB Oct 22, 2024

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

test/integration/client-side-encryption/driver.test.ts Outdated Show resolved Hide resolved
});

it(
'the command should not fail due to a server error',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'the command should not fail due to a server error',
'the command succeeds',

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

Comment on lines 138 to 141
client = new MongoClient(`mongodb://localhost:${mongocryptdTestPort}/?timeoutMS=1000`, {
monitorCommands: true
family: 6,
monitorCommands: true,
serverSelectionTimeoutMS: 2000
Copy link
Contributor

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;
Copy link
Contributor

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.

Suggested change
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() {} )

Copy link
Contributor Author

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
encryptedClient.close();
await encryptedClient.close();

Copy link
Contributor Author

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 () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

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.

Comment on lines 583 to 588
const err = await encryptedClient
.db('test')
.collection('test')
.insertOne({ a: 1 })
.catch(e => e);
expect(err).to.be.instanceOf(MongoOperationTimeoutError);
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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 () {
Copy link
Contributor

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

@baileympearson baileympearson merged commit bc05c4b into NODE-6090 Oct 25, 2024
18 of 27 checks passed
@baileympearson baileympearson deleted the NODE-6390/auto-encryption-csot branch October 25, 2024 17:01
nbbeeken added a commit that referenced this pull request Nov 1, 2024
Co-authored-by: Warren James <[email protected]>
Co-authored-by: Neal Beeken <[email protected]>
Co-authored-by: Bailey Pearson <[email protected]>
nbbeeken added a commit that referenced this pull request Nov 5, 2024
Co-authored-by: Warren James <[email protected]>
Co-authored-by: Neal Beeken <[email protected]>
Co-authored-by: Bailey Pearson <[email protected]>
dariakp pushed a commit that referenced this pull request Nov 6, 2024
Co-authored-by: Warren James <[email protected]>
Co-authored-by: Neal Beeken <[email protected]>
Co-authored-by: Bailey Pearson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants