-
Notifications
You must be signed in to change notification settings - Fork 245
DRIVERS-2985: Allow on-demand client metadata updates after MongoClient initialization. #1798
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
Changes from 17 commits
026c92b
a9eddb4
324019d
ab28ac3
03b5c1d
450528c
5ce8b92
c6a042b
e02503b
1faef56
8fc6f1c
c572c4d
0b7fbfa
dfde2d1
9f58bfb
b4a4b0e
4be80aa
f0315f4
da284da
72f1150
ae795a6
a34752b
43dea26
944329d
37456ca
c77aa66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,3 +82,160 @@ the following sets of environment variables: | |
2. Create and connect a `Connection` object that connects to the server that returns the mocked response. | ||
|
||
3. Assert that no error is raised. | ||
|
||
## Client Metadata Update Prose Tests | ||
|
||
Drivers that do not emit events for commands issued as part of the handshake with the server will need to create a | ||
test-only backdoor mechanism to intercept the handshake `hello` command for verification purposes. | ||
|
||
### Test 1: Test that the driver updates metadata | ||
|
||
Drivers should verify that metadata provided after `MongoClient` initialization is appended, not replaced, and is | ||
visible in the `hello` command of new connections. | ||
|
||
There are multiple test cases parameterized with `DriverInfoOptions` to be appended after `MongoClient` initialization. | ||
Before each test case, perform the setup. | ||
|
||
#### Setup | ||
|
||
1. Create a `MongoClient` instance with the following: | ||
|
||
- `maxIdleTimeMS` set to `1ms` | ||
|
||
- Wrapping library metadata: | ||
|
||
| Field | Value | | ||
| -------- | ---------------- | | ||
| name | library | | ||
| version | 1.2 | | ||
| platform | Library Platform | | ||
|
||
2. Send a `ping` command to the server and verify that the command succeeds. | ||
|
||
3. Save intercepted `client` document as `initialClientMetadata`. | ||
|
||
4. Wait 5ms for the connection to become idle. | ||
|
||
#### Parameterized test cases | ||
|
||
| Case | Name | Version | Platform | | ||
| ---- | --------- | ------- | ------------------ | | ||
| 1 | framework | 2.0 | Framework Platform | | ||
| 2 | framework | 2.0 | null | | ||
| 3 | framework | null | Framework Platform | | ||
| 4 | framework | null | null | | ||
|
||
#### Running a test case | ||
|
||
1. Append the `DriverInfoOptions` from the selected test case to the `MongoClient` metadata. | ||
|
||
2. Send a `ping` command to the server and verify: | ||
|
||
- The command succeeds. | ||
|
||
- The framework metadata is appended to the existing `DriverInfoOptions` in the `client.driver` fields of the `hello` | ||
command, with values separated by a pipe `|`. | ||
|
||
- `client.driver.name`: | ||
- If test case's name is non-null: `library|<name>` | ||
- Otherwise, the field remains unchanged: `library` | ||
- `client.driver.version`: | ||
- If test case's version is non-null: `1.2|<version>` | ||
- Otherwise, the field remains unchanged: `1.2` | ||
- `client.driver.platform`: | ||
- If test case's platform is non-null: `Library Platform|<platform>` | ||
- Otherwise, the field remains unchanged: `Library Platform` | ||
|
||
- All other subfields in the `client` document remain unchanged from `initialClientMetadata`. | ||
|
||
## Test 2: Multiple Successive Metadata Updates | ||
|
||
Drivers should verify that after `MongoClient` initialization, metadata can be updated multiple times, not replaced, and | ||
is visible in the `hello` command of new connections. | ||
|
||
There are multiple test cases parameterized with `DriverInfoOptions` to be appended after a previous metadata update. | ||
Before each test case, perform the setup. | ||
|
||
### Setup | ||
|
||
1. Create a `MongoClient` instance with: | ||
|
||
- `maxIdleTimeMS` set to `1ms` | ||
|
||
2. Append the following `DriverInfoOptions` to the `MongoClient` metadata: | ||
|
||
| Field | Value | | ||
| -------- | ---------------- | | ||
| name | library | | ||
| version | 1.2 | | ||
| platform | Library Platform | | ||
|
||
3. Send a `ping` command to the server and verify that the command succeeds. | ||
|
||
4. Save intercepted `client` document as `updatedClientMetadata`. | ||
|
||
5. Wait 5ms for the connection to become idle. | ||
|
||
#### Parameterized test cases | ||
|
||
| Case | Name | Version | Platform | | ||
| ---- | --------- | ------- | ------------------ | | ||
| 1 | framework | 2.0 | Framework Platform | | ||
| 2 | framework | 2.0 | null | | ||
| 3 | framework | null | Framework Platform | | ||
| 4 | framework | null | null | | ||
|
||
#### Running a test case | ||
|
||
1. Append the `DriverInfoOptions` from the selected test case to the `MongoClient` metadata. | ||
|
||
2. Send a `ping` command to the server and verify: | ||
|
||
- The command succeeds. | ||
|
||
- The framework metadata is appended to the existing `DriverInfoOptions` in the `client.driver` fields of the `hello` | ||
command, with values separated by a pipe `|`. | ||
|
||
- `client.driver.name`: | ||
- If test case's name is non-null: `library|<name>` | ||
- Otherwise, the field remains unchanged: `library` | ||
- `client.driver.version`: | ||
- If test case's version is non-null: `1.2|<version>` | ||
- Otherwise, the field remains unchanged: `1.2` | ||
- `client.driver.platform`: | ||
- If test case's platform is non-null: `Library Platform|<platform>` | ||
- Otherwise, the field remains unchanged: `Library Platform` | ||
|
||
- All other subfields in the `client` document remain unchanged from `updatedClientMetadata`. | ||
|
||
### Test 3: Test that metadata is not updated on established connections | ||
|
||
Drivers should verify that appending metadata after `MongoClient` initialization does **not** close existing | ||
connections, and that no new `hello` command is sent. | ||
|
||
1. Create a `MongoClient` instance with wrapping library metadata: | ||
|
||
| Field | Value | | ||
| -------- | ---------------- | | ||
| name | library | | ||
| version | 1.2 | | ||
| platform | Library Platform | | ||
|
||
2. Send a `ping` command to the server and verify: | ||
|
||
- The command succeeds. | ||
- The wrapping library metadata is appended to the respective `client.driver` fields of the `hello` command. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we simplify this test by removing the "library metadata" in step 1 and removing this assert from step 2? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch - I missed removing the assertions in test 3. Removed assertions and library metadata in f0315f4, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, couldn't this particular test be a unified spec test? It doesn't rely on any mocking. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, good point - it makes sense to convert this to a unified test. I’ve updated it accordingly. I also added an assertion to verify no new connection is created. Since unified tests don’t assume a test backdoor, we can’t directly assert on handshake commands. However, verifying that no new connection is established indirectly ensures no hello was sent during the handshake. Any subsequent hello's over an existing connection would appear as regular commands and cause the test to fail. |
||
|
||
3. Append the following `DriverInfoOptions` to the `MongoClient` metadata: | ||
|
||
| Field | Value | | ||
| -------- | ------------------ | | ||
| name | framework | | ||
| version | 2.0 | | ||
| platform | Framework Platform | | ||
|
||
4. Send a `ping` command to the server and verify: | ||
|
||
- The command succeeds. | ||
- No `hello` command is sent. | ||
- No `ConnectionClosedEvent` is emitted. |
Uh oh!
There was an error while loading. Please reload this page.