Skip to content

Commit 932e7e4

Browse files
authored
CDRIVER-4062 test load balancer on evg (#837)
Add tasks to the Evergreen configuration based to test against a loadbalanced cluster. - Tests with auth+SSL and with no auth+SSL on both server version 5.0 and latest. - Runs tests against: new load balanced tests, all unified tests, retryable reads, retryable writes, change streams, and the C driver specific /loadbalanced/* tests. Update test-libmongoc to support testing against a load balancer. - Support the environment variable MONGOC_TEST_LOADBALANCED to enable testing against load balancers in test-libmongoc. Support the environment variables SINGLE_MONGOS_LB_URI, MULTI_MONGOS_LB_URI to set URIs for test clients. - Mock the serviceId when MONGOC_TEST_LOADBALANCED is true. - Support multiple occurrences of the -l flag in test-libmongoc and alias the flag as --match. - Remove unnecessary constraint of retryable writes tests for replica sets. CDRIVER-4060 add remaining support to the unified test runner for the new loadbalancer spec tests. - Iterate the first result of a FindCursor in the createFindCursor operation. - Support appname as a URI parameter. - Skip listening or comparing CMAP (Connection Monitoring and Pooling) events, since the C driver does not implement CMAP.
1 parent 0d6a8ba commit 932e7e4

File tree

99 files changed

+4843
-865
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+4843
-865
lines changed

.evergreen/config.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ functions:
440440
export MONGOC_TEST_GCP_EMAIL="${client_side_encryption_gcp_email}"
441441
export MONGOC_TEST_GCP_PRIVATEKEY="${client_side_encryption_gcp_privatekey}"
442442
fi
443+
export LOADBALANCED=${LOADBALANCED}
444+
export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}"
445+
export MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}"
443446
set -o errexit
444447
sh .evergreen/run-tests.sh
445448
run tests bson:
@@ -26547,6 +26550,114 @@ tasks:
2654726550
set -o errexit
2654826551
export LD_LIBRARY_PATH=$(pwd)/install-dir/lib
2654926552
CERT_TYPE=ecdsa .evergreen/run-ocsp-cache-test.sh
26553+
- name: test-loadbalanced-asan-auth-openssl-5.0
26554+
tags:
26555+
- '5.0'
26556+
- test-asan
26557+
exec_timeout_secs: 3600
26558+
depends_on:
26559+
name: debug-compile-asan-clang-openssl
26560+
commands:
26561+
- func: fetch build
26562+
vars:
26563+
BUILD_NAME: debug-compile-asan-clang-openssl
26564+
- func: bootstrap mongo-orchestration
26565+
vars:
26566+
AUTH: auth
26567+
SSL: ssl
26568+
TOPOLOGY: sharded_cluster
26569+
VERSION: '5.0'
26570+
- func: clone drivers-evergreen-tools
26571+
- func: start load balancer
26572+
vars:
26573+
MONGODB_URI: mongodb://localhost:27017,localhost:27018
26574+
- func: run tests
26575+
vars:
26576+
ASAN: 'on'
26577+
AUTH: auth
26578+
LOADBALANCED: loadbalanced
26579+
SSL: ssl
26580+
- name: test-loadbalanced-asan-auth-openssl-latest
26581+
tags:
26582+
- latest
26583+
- test-asan
26584+
exec_timeout_secs: 3600
26585+
depends_on:
26586+
name: debug-compile-asan-clang-openssl
26587+
commands:
26588+
- func: fetch build
26589+
vars:
26590+
BUILD_NAME: debug-compile-asan-clang-openssl
26591+
- func: bootstrap mongo-orchestration
26592+
vars:
26593+
AUTH: auth
26594+
SSL: ssl
26595+
TOPOLOGY: sharded_cluster
26596+
VERSION: latest
26597+
- func: clone drivers-evergreen-tools
26598+
- func: start load balancer
26599+
vars:
26600+
MONGODB_URI: mongodb://localhost:27017,localhost:27018
26601+
- func: run tests
26602+
vars:
26603+
ASAN: 'on'
26604+
AUTH: auth
26605+
LOADBALANCED: loadbalanced
26606+
SSL: ssl
26607+
- name: test-loadbalanced-asan-noauth-nossl-5.0
26608+
tags:
26609+
- '5.0'
26610+
- test-asan
26611+
exec_timeout_secs: 3600
26612+
depends_on:
26613+
name: debug-compile-asan-clang-openssl
26614+
commands:
26615+
- func: fetch build
26616+
vars:
26617+
BUILD_NAME: debug-compile-asan-clang-openssl
26618+
- func: bootstrap mongo-orchestration
26619+
vars:
26620+
AUTH: noauth
26621+
SSL: nossl
26622+
TOPOLOGY: sharded_cluster
26623+
VERSION: '5.0'
26624+
- func: clone drivers-evergreen-tools
26625+
- func: start load balancer
26626+
vars:
26627+
MONGODB_URI: mongodb://localhost:27017,localhost:27018
26628+
- func: run tests
26629+
vars:
26630+
ASAN: 'on'
26631+
AUTH: noauth
26632+
LOADBALANCED: loadbalanced
26633+
SSL: nossl
26634+
- name: test-loadbalanced-asan-noauth-nossl-latest
26635+
tags:
26636+
- latest
26637+
- test-asan
26638+
exec_timeout_secs: 3600
26639+
depends_on:
26640+
name: debug-compile-asan-clang-openssl
26641+
commands:
26642+
- func: fetch build
26643+
vars:
26644+
BUILD_NAME: debug-compile-asan-clang-openssl
26645+
- func: bootstrap mongo-orchestration
26646+
vars:
26647+
AUTH: noauth
26648+
SSL: nossl
26649+
TOPOLOGY: sharded_cluster
26650+
VERSION: latest
26651+
- func: clone drivers-evergreen-tools
26652+
- func: start load balancer
26653+
vars:
26654+
MONGODB_URI: mongodb://localhost:27017,localhost:27018
26655+
- func: run tests
26656+
vars:
26657+
ASAN: 'on'
26658+
AUTH: noauth
26659+
LOADBALANCED: loadbalanced
26660+
SSL: nossl
2655026661
buildvariants:
2655126662
- name: releng
2655226663
display_name: '**Release Archive Creator'

.evergreen/download-mongodb.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ get_mongodb_download_url_for ()
5151
_DISTRO=$1
5252
_VERSION=$2
5353

54-
VERSION_50="5.0.0-rc0"
55-
VERSION_44="4.4.3"
56-
VERSION_42="4.2.11"
57-
VERSION_40="4.0.22"
58-
VERSION_36="3.6.21"
54+
VERSION_50="5.0.0"
55+
VERSION_44="4.4.6"
56+
VERSION_42="4.2.15"
57+
VERSION_40="4.0.25"
58+
VERSION_36="3.6.23"
5959
VERSION_34="3.4.24"
6060
VERSION_32="3.2.22"
6161
VERSION_30="3.0.15"

.evergreen/run-tests.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ SSL=${SSL:-nossl}
88
URI=${URI:-}
99
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
1010
DNS=${DNS:-nodns}
11+
LOADBALANCED=${LOADBALANCED:-noloadbalanced}
1112

1213
# AddressSanitizer configuration
1314
export ASAN_OPTIONS="detect_leaks=1 abort_on_error=1 symbolize=1"
@@ -91,6 +92,29 @@ check_mongocryptd() {
9192

9293
export MONGOC_TEST_MONITORING_VERBOSE=on
9394

95+
if [ "$LOADBALANCED" != "noloadbalanced" ]; then
96+
if [ -z "$SINGLE_MONGOS_LB_URI" -o -z "$MULTI_MONGOS_LB_URI" ]; then
97+
echo "SINGLE_MONGOS_LB_URI and MULTI_MONGOS_LB_URI environment variables required."
98+
exit 1
99+
fi
100+
101+
export MONGOC_TEST_LOADBALANCED=ON
102+
103+
TEST_ARGS="$TEST_ARGS -l /unified/*"
104+
TEST_ARGS="$TEST_ARGS -l /retryable_reads/*"
105+
TEST_ARGS="$TEST_ARGS -l /retryable_writes/*"
106+
TEST_ARGS="$TEST_ARGS -l /change_streams/*"
107+
TEST_ARGS="$TEST_ARGS -l /loadbalanced/*"
108+
TEST_ARGS="$TEST_ARGS -l /load_balancers/*"
109+
TEST_ARGS="$TEST_ARGS -l /crud/unified/*"
110+
TEST_ARGS="$TEST_ARGS -l /transactions/unified/*"
111+
TEST_ARGS="$TEST_ARGS -l /collection-management/*"
112+
TEST_ARGS="$TEST_ARGS -l /sessions/unified/*"
113+
TEST_ARGS="$TEST_ARGS -l /change_streams/unified/*"
114+
TEST_ARGS="$TEST_ARGS -l /versioned_api/*"
115+
TEST_ARGS="$TEST_ARGS -l /command_monitoring/unified/*"
116+
fi
117+
94118
case "$OS" in
95119
cygwin*)
96120
export PATH=$PATH:/cygdrive/c/mongodb/bin:/cygdrive/c/libmongocrypt/bin

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ To test with a declared API version, you can pass the API version using an envir
262262

263263
This will ensure that all tests declare the indicated API version when connecting to a server.
264264

265+
To test a load balanced deployment, set the following environment variables:
266+
267+
* `MONGOC_TEST_LOADBALANCED=on`
268+
* `SINGLE_MONGOS_LB_URI=<string>` to a MongoDB URI with a host of a load balancer fronting one mongos.
269+
* `MULTI_MONGOS_LB_URI=<string>` to a MongoDB URI with a host of a load balancer fronting multiple mongos processes.
270+
265271
All tests should pass before submitting a patch.
266272

267273
## Configuring the test runner

build/evergreen_config_lib/functions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@
311311
export MONGOC_TEST_GCP_EMAIL="${client_side_encryption_gcp_email}"
312312
export MONGOC_TEST_GCP_PRIVATEKEY="${client_side_encryption_gcp_privatekey}"
313313
fi
314+
export LOADBALANCED=${LOADBALANCED}
315+
export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}"
316+
export MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}"
314317
set -o errexit
315318
sh .evergreen/run-tests.sh
316319
'''),

build/evergreen_config_lib/tasks.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,4 +1074,71 @@ def _check_allowed(self):
10741074

10751075
all_tasks = chain(all_tasks, OCSPTask.matrix())
10761076

1077+
class LoadBalancedTask(MatrixTask):
1078+
axes = OD([
1079+
('asan', [True]),
1080+
('build_ssl', ['openssl']), # The SSL library the C driver is built with.
1081+
('test_ssl', [True, False]), # Whether tests are run with SSL connections.
1082+
('test_auth', [True, False]),
1083+
('version', ['5.0', 'latest'])
1084+
])
1085+
1086+
def _check_allowed (self):
1087+
# Test with both SSL and auth, or neither.
1088+
prohibit (self.test_ssl != self.test_auth)
1089+
1090+
def __init__(self, *args, **kwargs):
1091+
super(LoadBalancedTask, self).__init__(*args, **kwargs)
1092+
if self.asan and self.build_ssl == "openssl":
1093+
self.add_dependency ('debug-compile-asan-clang-openssl')
1094+
self.add_tags('test-asan')
1095+
else:
1096+
raise RuntimeError ("unimplemented configuration for LoadBalancedTask")
1097+
1098+
self.add_tags(self.version)
1099+
self.options['exec_timeout_secs'] = 3600
1100+
1101+
# Return the task name.
1102+
# Example: test-loadbalanced-asan-auth-openssl-latest
1103+
@property
1104+
def name(self):
1105+
name = "test-loadbalanced"
1106+
if self.asan:
1107+
name += "-asan"
1108+
if self.test_auth:
1109+
name += "-auth"
1110+
else:
1111+
name += "-noauth"
1112+
if self.test_ssl:
1113+
name += "-" + self.build_ssl
1114+
else:
1115+
name += "-nossl"
1116+
if self.version:
1117+
name += "-" + self.version
1118+
return name
1119+
1120+
def to_dict(self):
1121+
task = super(MatrixTask, self).to_dict()
1122+
commands = task['commands']
1123+
commands.append(
1124+
func('fetch build', BUILD_NAME=self.depends_on['name']))
1125+
1126+
1127+
orchestration = bootstrap(TOPOLOGY='sharded_cluster',
1128+
AUTH='auth' if self.test_auth else 'noauth',
1129+
SSL='ssl' if self.test_ssl else 'nossl',
1130+
VERSION=self.version)
1131+
commands.append(orchestration)
1132+
commands.append (func("clone drivers-evergreen-tools"))
1133+
commands.append (func("start load balancer",
1134+
MONGODB_URI="mongodb://localhost:27017,localhost:27018"))
1135+
commands.append(run_tests(ASAN='on' if self.asan else 'off',
1136+
SSL='ssl' if self.test_ssl else 'nossl',
1137+
AUTH='auth' if self.test_auth else 'noauth',
1138+
LOADBALANCED='loadbalanced'))
1139+
1140+
return task
1141+
1142+
all_tasks = chain(all_tasks, LoadBalancedTask.matrix())
1143+
10771144
all_tasks = list(all_tasks)

build/evergreen_config_lib/variants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def days(n):
657657
], {}, batchtime=days(7)),
658658
Variant ('packaging', 'Linux Distro Packaging', 'ubuntu1804-test', [
659659
'debian-package-build',
660-
OD([('name', 'rpm-package-build'), ('distros', ['rhel80-test'])]),
660+
OD([('name', 'rpm-package-build'), ('distros', ['rhel82-arm64-small'])]),
661661
], {}, batchtime=days(1)),
662662
Variant('tsan-ubuntu',
663663
'Thread Sanitizer (TSAN) Tests (Ubuntu 18.04)',

src/libmongoc/src/mongoc/mongoc-cluster.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,7 @@ _mongoc_cluster_stream_for_server (mongoc_cluster_t *cluster,
23212321
mongoc_server_stream_cleanup (server_stream);
23222322
mongoc_cluster_disconnect_node (cluster, server_id);
23232323
bson_mutex_unlock (&topology->mutex);
2324+
_mongoc_bson_init_if_set (reply);
23242325
return NULL;
23252326
}
23262327
}

src/libmongoc/src/mongoc/mongoc-cmd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,9 @@ mongoc_cmd_parts_assemble (mongoc_cmd_parts_t *parts,
10221022
}
10231023

10241024
ret = true;
1025-
} else if (server_type == MONGOC_SERVER_MONGOS) {
1025+
} else if (server_type == MONGOC_SERVER_MONGOS ||
1026+
server_stream->topology_type == MONGOC_TOPOLOGY_LOAD_BALANCED) {
1027+
/* TODO (CDRIVER-4117) remove the check of the topology description type. */
10261028
_mongoc_cmd_parts_assemble_mongos (parts, server_stream);
10271029
ret = true;
10281030
} else {

src/libmongoc/src/mongoc/mongoc-server-description-private.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,10 @@ bool
200200
mongoc_server_description_has_service_id (
201201
const mongoc_server_description_t *description);
202202

203+
/* mongoc_global_mock_service_id is only used for testing. The test runner sets
204+
* this to true when testing against a load balanced deployment to mock the
205+
* presence of a serviceId field in the "hello" response. The purpose of this is
206+
* further described in the Load Balancer test README. */
207+
extern bool mongoc_global_mock_service_id;
208+
203209
#endif

src/libmongoc/src/mongoc/mongoc-server-description.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ static bson_oid_t kObjectIdZero = {{0}};
3333

3434
const bson_oid_t kZeroServiceId = {{0}};
3535

36+
bool mongoc_global_mock_service_id = false;
37+
3638
static bool
3739
_match_tag_set (const mongoc_server_description_t *sd,
3840
bson_iter_t *tag_set_iter);
@@ -735,6 +737,16 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
735737
}
736738
}
737739

740+
741+
if (mongoc_global_mock_service_id) {
742+
bson_iter_t pid_iter;
743+
744+
if (bson_iter_init_find (&pid_iter, &sd->topology_version, "processId") &&
745+
BSON_ITER_HOLDS_OID (&pid_iter)) {
746+
bson_oid_copy (bson_iter_oid (&pid_iter), &sd->service_id);
747+
}
748+
}
749+
738750
if (is_shard) {
739751
sd->type = MONGOC_SERVER_MONGOS;
740752
} else if (sd->set_name) {

0 commit comments

Comments
 (0)