Skip to content

Commit ef71b35

Browse files
nbbeekenljhaywar
authored andcommitted
chore: add instructions on howto test specialized environments (#3009)
1 parent 76ea9e6 commit ef71b35

File tree

4 files changed

+138
-14
lines changed

4 files changed

+138
-14
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ lib/
6262
output
6363

6464
serverless-expansion.yml
65+
serverless.env
66+
67+
lb-expansion.yml
68+
lb.env

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ If you just want to get formatting and linting working automatically use these s
5454
- Start a mongod standalone with our [cluster_setup.sh](test/tools/cluster_setup.sh) script
5555
- Usage: `./test/tools/cluster_setup.sh server`
5656
- Run the tests with `npm test`
57+
- Read further in [test/readme.md](test/readme.md) if you need to test a special environment like CSFLE, or Serverless.
5758

5859
### Tests FAQ
5960

README.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
The official [MongoDB](https://www.mongodb.com/) driver for Node.js.
44

5-
**Upgrading to version 4? Take a look at our [upgrade guide here](https://github.com/mongodb/node-mongodb-native/blob/4.1/docs/CHANGES_4.0.0.md)!**
5+
**Upgrading to version 4? Take a look at our [upgrade guide here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/docs/CHANGES_4.0.0.md)!**
66

77
## Quick Links
88

9-
| what | where |
10-
| ------------- | ------------------------------------------------------------------------------------------------------ |
11-
| documentation | [docs.mongodb.com/drivers/node](https://docs.mongodb.com/drivers/node) |
12-
| api-doc | [mongodb.github.io/node-mongodb-native/4.1/](https://mongodb.github.io/node-mongodb-native/4.1/) |
13-
| npm package | [www.npmjs.com/package/mongodb](https://www.npmjs.com/package/mongodb) |
14-
| source | [github.com/mongodb/node-mongodb-native](https://github.com/mongodb/node-mongodb-native) |
15-
| mongodb | [www.mongodb.com](https://www.mongodb.com) |
16-
| changelog | [HISTORY.md](https://github.com/mongodb/node-mongodb-native/blob/4.1/HISTORY.md) |
17-
| upgrade to v4 | [docs/CHANGES_4.0.0.md](https://github.com/mongodb/node-mongodb-native/blob/4.1/docs/CHANGES_4.0.0.md) |
9+
| what | where |
10+
| ------------- | ------------------------------------------------------------------------------------------------------- |
11+
| documentation | [docs.mongodb.com/drivers/node](https://docs.mongodb.com/drivers/node) |
12+
| api-doc | [mongodb.github.io/node-mongodb-native/4.1/](https://mongodb.github.io/node-mongodb-native/4.1/) |
13+
| npm package | [www.npmjs.com/package/mongodb](https://www.npmjs.com/package/mongodb) |
14+
| source | [github.com/mongodb/node-mongodb-native](https://github.com/mongodb/node-mongodb-native) |
15+
| mongodb | [www.mongodb.com](https://www.mongodb.com) |
16+
| changelog | [HISTORY.md](https://github.com/mongodb/node-mongodb-native/blob/HEAD/HISTORY.md) |
17+
| upgrade to v4 | [docs/CHANGES_4.0.0.md](https://github.com/mongodb/node-mongodb-native/blob/HEAD/docs/CHANGES_4.0.0.md) |
18+
| contributing | [CONTRIBUTING.md](https://github.com/mongodb/node-mongodb-native/blob/HEAD/CONTRIBUTING.md) |
1819

1920
### Bugs / Feature Requests
2021

@@ -34,7 +35,7 @@ For issues with, questions about, or feedback for the Node.js driver, please loo
3435

3536
### Change Log
3637

37-
Change history can be found in [`HISTORY.md`](https://github.com/mongodb/node-mongodb-native/blob/4.1/HISTORY.md).
38+
Change history can be found in [`HISTORY.md`](https://github.com/mongodb/node-mongodb-native/blob/HEAD/HISTORY.md).
3839

3940
### Compatibility
4041

@@ -78,7 +79,7 @@ The MongoDB driver depends on several other packages. These are:
7879
- [kerberos](https://github.com/mongodb-js/kerberos)
7980
- [mongodb-client-encryption](https://github.com/mongodb/libmongocrypt#readme)
8081

81-
Some of these packages include native C++ extensions, consult the [trouble shooting guide here](https://github.com/mongodb/node-mongodb-native/blob/4.1/docs/native-extensions.md) if you run into issues.
82+
Some of these packages include native C++ extensions. Consult the [trouble shooting guide here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/docs/native-extensions.md) if you run into issues.
8283

8384
## Quick Start
8485

@@ -239,7 +240,7 @@ For more detailed information, see the [indexing strategies page](https://docs.m
239240

240241
## Error Handling
241242

242-
If you need to filter certain errors from our driver we have a helpful tree of errors described in [docs/errors.md](https://github.com/mongodb/node-mongodb-native/blob/4.1/docs/errors.md).
243+
If you need to filter certain errors from our driver we have a helpful tree of errors described in [docs/errors.md](https://github.com/mongodb/node-mongodb-native/blob/HEAD/docs/errors.md).
243244

244245
It is our recommendation to use `instanceof` checks on errors and to avoid relying on parsing `error.message` and `error.name` strings in your code.
245246
We guarantee `instanceof` checks will pass according to semver guidelines, but errors may be sub-classed or their messages may change at any time, even patch releases, as we see fit to increase the helpfulness of the errors.
@@ -275,4 +276,4 @@ try {
275276
[Apache 2.0](LICENSE.md)
276277

277278
© 2009-2012 Christian Amor Kvalheim
278-
© 2012-present MongoDB [Contributors](https://github.com/mongodb/node-mongodb-native/blob/4.1/CONTRIBUTORS.md)
279+
© 2012-present MongoDB [Contributors](https://github.com/mongodb/node-mongodb-native/blob/HEAD/CONTRIBUTORS.md)

test/readme.md

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# How to test
2+
3+
## Special Environments
4+
5+
There are collections of tests that test features requiring a specialized set of environment variables to be generated and set in order to run. Look below for the section that applies to the feature you are trying to test.
6+
7+
### Serverless
8+
9+
Find the following script in driver-evergreen-tools and make sure you have the following environment variables defined.
10+
_**Remember**_ some of these are sensitive credentials so keep them safe and only put them in your environment when you need them.
11+
12+
- `PROJECT`
13+
- `SERVERLESS_DRIVERS_GROUP`
14+
- `SERVERLESS_API_PUBLIC_KEY`
15+
- `SERVERLESS_API_PRIVATE_KEY`
16+
- `SERVERLESS_ATLAS_USER`
17+
- `SERVERLESS_ATLAS_PASSWORD`
18+
- `LOADBALANCED`
19+
20+
```sh
21+
$DRIVERS_TOOLS/.evergreen/serverless/create-instance.sh
22+
```
23+
24+
this will output an evergreen expansion in `serverless-expansion.yml` in the current working directory.
25+
26+
```yml
27+
MONGODB_URI: xxx
28+
MONGODB_SRV_URI: xxx
29+
SERVERLESS_INSTANCE_NAME: xxx
30+
SSL: xxx
31+
AUTH: xxx
32+
TOPOLOGY: xxx
33+
SERVERLESS: xxx
34+
MULTI_ATLASPROXY_SERVERLESS_URI: xxx
35+
SINGLE_ATLASPROXY_SERVERLESS_URI: xxx
36+
```
37+
38+
Since it's a flat yaml file, you can run the following to get a sourceable environment file:
39+
40+
```sh
41+
cat serverless-expansion.yml | sed 's/: /=/g' > serverless.env
42+
```
43+
44+
Before sourcing `serverless.env`, make some adjustments that are equivalent to what our EVG does:
45+
46+
- Change `MONGODB_URI` to be the same as `SINGLE_ATLASPROXY_SERVERLESS_URI`
47+
- Add `SINGLE_MONGOS_LB_URI` and `MULTI_MONGOS_LB_URI` and set them to `SINGLE_ATLASPROXY_SERVERLESS_URI`
48+
49+
Lastly, comment out the `source` of `install-dependencies.sh` command in `.evergreen/run-serverless-tests.sh` and you can run that script directly to test serverless instances from your local machine.
50+
51+
### Load Balanced
52+
53+
You'll first need to start a sharded cluster using your favorite MongoDB orchestration tool of choice.
54+
The tool should create a cluster with two mongos so you have a uri like `MONGODB_URI=mongodb://host1,host2/`
55+
Then you need to start a load balancer: you can install `haproxy` on macos via `brew` and use the script provided in drivers-evergreen-tools.
56+
57+
```sh
58+
$DRIVERS_TOOLS/.evergreen/run-load-balancer.sh start
59+
```
60+
61+
This will output an evergreen expansion file: `lb-expansion.yml`
62+
63+
```yaml
64+
SINGLE_MONGOS_LB_URI: "mongodb://127.0.0.1:8000/?loadBalanced=true"
65+
MULTI_MONGOS_LB_URI: "mongodb://127.0.0.1:8001/?loadBalanced=true"
66+
```
67+
68+
Since it's a flat yaml file, you can run the following to get a sourceable environment file:
69+
70+
```sh
71+
cat lb-expansion.yml | sed 's/: /=/g' > lb.env
72+
```
73+
74+
You have to add an additional environment variable to the end of this `lb.env` file:
75+
76+
```sh
77+
FAKE_MONGODB_SERVICE_ID="true"
78+
```
79+
80+
This enables logic in the driver to stick in a fake service id on responses since that's what a real LB deployment is required to do.
81+
With those variables sourced, you can run the whole test suite as you normally would.
82+
83+
> Please note, `FAKE_MONGODB_SERVICE_ID` will no longer be needed with the completion of [NODE-3431](https://jira.mongodb.org/browse/NODE-3431).
84+
85+
```sh
86+
npm run check:test
87+
```
88+
89+
Take note of the `[ topology type: load-balanced ]` printout from mocha to make sure it picked up the environment as expected.
90+
91+
When you are done testing you can shutdown the haproxy load balancer with:
92+
93+
```sh
94+
$DRIVERS_TOOLS/.evergreen/run-load-balancer.sh stop
95+
```
96+
97+
### CSFLE
98+
99+
As long as certain environment variables are present and mongodb-client-encryption is installed, FLE will run with a regular mocha execution: `npm run check:test`.
100+
101+
Define the following variables in your environment:
102+
103+
- `AWS_ACCESS_KEY_ID`
104+
- `AWS_SECRET_ACCESS_KEY`
105+
- `CSFLE_KMS_PROVIDERS`
106+
- `AWS_REGION`
107+
- `AWS_CMK_ID`
108+
109+
### TODO Special Env Sections
110+
111+
- Kerberos
112+
- AWS Authentication
113+
- OCSP
114+
- TLS
115+
- Atlas Data Lake
116+
- LDAP
117+
- Snappy (maybe in general, how to test optional dependencies)
118+
- Atlas connectivity

0 commit comments

Comments
 (0)