Skip to content

Commit 9b28636

Browse files
committed
jesse + jeremy comments
- update handling of useMultipleMongoses in UTF - use mongoc_ prefix in mock global - clang format - clean up if/else branching
1 parent 83e3949 commit 9b28636

File tree

9 files changed

+55
-50
lines changed

9 files changed

+55
-50
lines changed

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

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

203-
extern bool global_mock_service_id;
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;
204208

205209
#endif

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

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

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

36-
bool global_mock_service_id = false;
36+
bool mongoc_global_mock_service_id = false;
3737

3838
static bool
3939
_match_tag_set (const mongoc_server_description_t *sd,
@@ -738,7 +738,7 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
738738
}
739739

740740

741-
if (global_mock_service_id) {
741+
if (mongoc_global_mock_service_id) {
742742
bson_iter_t pid_iter;
743743

744744
if (bson_iter_init_find (&pid_iter, &sd->topology_version, "processId") &&

src/libmongoc/tests/TestSuite.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -886,24 +886,21 @@ bool
886886
test_matches (TestSuite *suite, Test *test)
887887
{
888888
int i;
889-
bool matches;
890889

891890
/* If no match patterns were provided, then assume all match. */
892891
if (suite->match_patterns.len == 0) {
893-
matches = true;
894-
} else {
895-
matches = false;
896-
for (i = 0; i < suite->match_patterns.len; i++) {
897-
char *pattern =
898-
_mongoc_array_index (&suite->match_patterns, char *, i);
899-
if (TestSuite_TestMatchesName (suite, test, pattern)) {
900-
matches = true;
901-
break;
902-
}
892+
return true;
893+
}
894+
895+
for (i = 0; i < suite->match_patterns.len; i++) {
896+
char *pattern =
897+
_mongoc_array_index (&suite->match_patterns, char *, i);
898+
if (TestSuite_TestMatchesName (suite, test, pattern)) {
899+
return true;
903900
}
904901
}
905902

906-
return matches;
903+
return false;
907904
}
908905

909906
static int

src/libmongoc/tests/test-libmongoc.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,13 +1408,16 @@ test_framework_get_uri_multi_mongos_loadbalanced () {
14081408
char *uri_str_no_auth;
14091409
char *uri_str;
14101410
mongoc_uri_t *uri;
1411+
bson_error_t error;
14111412

14121413
uri_str_no_auth = _mongoc_getenv ("MULTI_MONGOS_LB_URI");
14131414
if (!uri_str_no_auth) {
14141415
test_error ("expected MULTI_MONGOS_LB_URI to be set");
14151416
}
14161417
uri_str = test_framework_add_user_password_from_env (uri_str_no_auth);
1417-
uri = mongoc_uri_new (uri_str);
1418+
uri = mongoc_uri_new_with_error (uri_str, &error);
1419+
1420+
ASSERT_OR_PRINT (uri, error);
14181421

14191422
bson_free (uri_str_no_auth);
14201423
bson_free (uri_str);
@@ -2951,7 +2954,7 @@ main (int argc, char *argv[])
29512954
test_generation_map_install (&suite);
29522955

29532956
if (test_framework_is_loadbalanced ()) {
2954-
global_mock_service_id = true;
2957+
mongoc_global_mock_service_id = true;
29552958
}
29562959

29572960
ret = TestSuite_Run (&suite);

src/libmongoc/tests/test-mongoc-loadbalanced.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,7 @@ test_post_handshake_error_clears_pool (void)
774774
static int
775775
skip_if_not_loadbalanced (void)
776776
{
777-
if (!test_framework_is_loadbalanced ()) {
778-
return 0;
779-
}
780-
return 1;
777+
return test_framework_is_loadbalanced () ? 1 : 0;
781778
}
782779

783780
void

src/libmongoc/tests/test-mongoc-retryable-writes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ retryable_writes_test_run_operation (json_test_ctx_t *ctx,
3535
static test_skip_t skips[] = {
3636
{"InsertOne fails after multiple retryable writeConcernErrors",
3737
"Waiting on CDRIVER-3790"},
38-
{0, 0}};
38+
{0}};
3939

4040
/* Callback for JSON tests from Retryable Writes Spec */
4141
static void

src/libmongoc/tests/unified/entity-map.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,21 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
343343
* host. If useMultipleMongoses is false, require that the connection string
344344
* has one host. If useMultipleMongoses unspecified, make no assertion.
345345
*/
346-
if (use_multiple_mongoses != NULL) {
347-
if (*use_multiple_mongoses && test_framework_is_loadbalanced ()) {
346+
if (test_framework_is_loadbalanced ()) {
347+
/* Quoting the unified test runner specification:
348+
* If the topology type is LoadBalanced, [...] If useMultipleMongoses is
349+
* true or unset, the test runner MUST use the URI of the load balancer
350+
* fronting multiple servers. Otherwise, the test runner MUST use the URI
351+
* of the load balancer fronting a single server.
352+
*/
353+
if (use_multiple_mongoses == NULL || *use_multiple_mongoses == true) {
348354
mongoc_uri_destroy (uri);
349355
uri = test_framework_get_uri_multi_mongos_loadbalanced ();
350-
} else {
351-
if (!test_framework_uri_apply_multi_mongos (
352-
uri, *use_multiple_mongoses, error)) {
353-
goto done;
354-
}
356+
}
357+
} else if (use_multiple_mongoses != NULL) {
358+
if (!test_framework_uri_apply_multi_mongos (
359+
uri, *use_multiple_mongoses, error)) {
360+
goto done;
355361
}
356362
}
357363

src/libmongoc/tests/unified/runner.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ test_runner_new (void)
381381
uri = test_framework_get_uri ();
382382
/* In load balanced mode, the internal client must use the SINGLE_LB_MONGOS_URI. */
383383
if (!test_framework_is_loadbalanced ()) {
384-
/* Always use multiple mongos's if speaking to a mongos.
384+
/* Always use multiple mongoses if speaking to a mongos.
385385
* Some test operations require communicating with all known mongos */
386386
if (!test_framework_uri_apply_multi_mongos (uri, true, &error)) {
387387
test_error ("error applying multiple mongos: %s", error.message);
@@ -1151,9 +1151,7 @@ test_check_expected_events_for_client (test_t *test,
11511151
* supported. */
11521152
ret = true;
11531153
goto done;
1154-
} else if (0 == strcmp (event_type, "command")) {
1155-
/* proceed. */
1156-
} else {
1154+
} else if (0 != strcmp (event_type, "command")) {
11571155
test_set_error (error, "unexpected event type: %s", event_type);
11581156
goto done;
11591157
}

src/libmongoc/tests/unified/util.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,23 @@ test_bson_util_install (TestSuite *suite)
166166

167167
/* TODO (CDRIVER-3525) add test support for CMAP events once the C driver
168168
* supports CMAP. */
169-
bool is_unsupported_event_type (const char* event_type) {
170-
char * unsupported_event_types[] = {
171-
"poolCreatedEvent",
172-
"poolReadyEvent",
173-
"poolClearedEvent",
174-
"poolClosedEvent",
175-
"connectionCreatedEvent",
176-
"connectionReadyEvent",
177-
"connectionClosedEvent",
178-
"connectionCheckOutStartedEvent",
179-
"connectionCheckOutFailedEvent",
180-
"connectionCheckedOutEvent",
181-
"connectionCheckedInEvent",
182-
NULL
183-
};
184-
185-
char ** iter;
169+
bool
170+
is_unsupported_event_type (const char *event_type)
171+
{
172+
char *unsupported_event_types[] = {"poolCreatedEvent",
173+
"poolReadyEvent",
174+
"poolClearedEvent",
175+
"poolClosedEvent",
176+
"connectionCreatedEvent",
177+
"connectionReadyEvent",
178+
"connectionClosedEvent",
179+
"connectionCheckOutStartedEvent",
180+
"connectionCheckOutFailedEvent",
181+
"connectionCheckedOutEvent",
182+
"connectionCheckedInEvent",
183+
NULL};
184+
185+
char **iter;
186186

187187
for (iter = unsupported_event_types; *iter != NULL; iter++) {
188188
if (0 == strcmp (event_type, *iter)) {

0 commit comments

Comments
 (0)