Skip to content

Commit f08d938

Browse files
committed
CDRIVER-3287 run mongos txn tests in evergreen
- Unify the transactions and with_transactions test runners - Skip tests due to readConcnern "snapshot" - Skip three failing tests that require investigating - Update all spec test JSON. Omits errors-client.json, waiting on CDRIVER-3215
1 parent e6cf2a3 commit f08d938

34 files changed

+1198
-365
lines changed

src/libmongoc/src/mongoc/mongoc-client-session.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define SESSION_NEVER_USED (-1)
2727

2828
#define WITH_TXN_TIMEOUT_MS (120 * 1000)
29-
#define DEFAULT_MAX_COMMIT_TIME_MS -1
29+
#define DEFAULT_MAX_COMMIT_TIME_MS 0
3030

3131
static void
3232
txn_opts_set (mongoc_transaction_opt_t *opts,
@@ -975,8 +975,8 @@ mongoc_client_session_with_transaction (
975975
GOTO (done);
976976
}
977977

978-
/* Whether or not we used local_reply above, use it now, but
979-
access it through active_reply so cleanup in DONE is simpler. */
978+
/* Whether or not we used local_reply above, use it now, but access it
979+
* through active_reply so cleanup in DONE is simpler. */
980980
bson_destroy (active_reply);
981981
active_reply = &local_reply;
982982

@@ -1005,8 +1005,7 @@ mongoc_client_session_with_transaction (
10051005
*
10061006
* Here, we don't want to set active_reply = NULL when we
10071007
* destroy, because we want it to point to an uninitialized
1008-
* bson_t
1009-
* at the top of this loop every time.*/
1008+
* bson_t at the top of this loop every time.*/
10101009
bson_destroy (active_reply);
10111010
continue;
10121011
}
@@ -1126,8 +1125,8 @@ mongoc_client_session_start_transaction (mongoc_client_session_t *session,
11261125
_mongoc_client_session_unpin (session);
11271126
session->txn.state = MONGOC_TRANSACTION_STARTING;
11281127
/* Transactions spec: "Drivers MUST clear a session's cached
1129-
* 'recoveryToken' when transitioning to the 'no transaction' or
1130-
* 'starting transaction' state." */
1128+
* 'recoveryToken' when transitioning to the 'no transaction' or
1129+
* 'starting transaction' state." */
11311130
bson_destroy (session->recovery_token);
11321131
session->recovery_token = NULL;
11331132

src/libmongoc/src/mongoc/mongoc-uri-private.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
BSON_BEGIN_DECLS
2626

2727

28-
2928
bool
3029
mongoc_uri_upsert_host_and_port (mongoc_uri_t *uri,
31-
const char *host_and_port,
32-
bson_error_t *error);
30+
const char *host_and_port,
31+
bson_error_t *error);
3332
bool
3433
mongoc_uri_upsert_host (mongoc_uri_t *uri,
3534
const char *host,
@@ -54,6 +53,10 @@ _mongoc_uri_requires_auth_negotiation (const mongoc_uri_t *uri);
5453
const char *
5554
mongoc_uri_canonicalize_option (const char *key);
5655

56+
mongoc_uri_t *
57+
_mongoc_uri_copy_and_replace_host_list (const mongoc_uri_t *original,
58+
const char *host);
59+
5760
BSON_END_DECLS
5861

5962

src/libmongoc/src/mongoc/mongoc-uri.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,3 +2670,17 @@ _mongoc_uri_requires_auth_negotiation (const mongoc_uri_t *uri)
26702670
{
26712671
return mongoc_uri_get_username (uri) && !mongoc_uri_get_auth_mechanism (uri);
26722672
}
2673+
2674+
2675+
/* A bit of a hack. Needed for multi mongos tests to create a URI with the same
2676+
* auth, SSL, and compressors settings but with only one specific host. */
2677+
mongoc_uri_t *
2678+
_mongoc_uri_copy_and_replace_host_list (const mongoc_uri_t *original,
2679+
const char *host)
2680+
{
2681+
mongoc_uri_t *uri = mongoc_uri_copy (original);
2682+
_mongoc_host_list_destroy_all (uri->hosts);
2683+
uri->hosts = bson_malloc0 (sizeof (mongoc_host_list_t));
2684+
_mongoc_host_list_from_string (uri->hosts, host);
2685+
return uri;
2686+
}

src/libmongoc/tests/json-test-operations.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "mongoc/mongoc-topology-private.h"
2727
#include "mongoc/mongoc-util-private.h"
2828
#include "mongoc/mongoc-util-private.h"
29+
#include "mongoc/mongoc-uri-private.h"
2930

3031
#include "json-test-operations.h"
3132
#include "json-test.h"
@@ -69,7 +70,8 @@ json_test_ctx_init (json_test_ctx_t *ctx,
6970
ctx->config = config;
7071
ctx->n_events = 0;
7172
bson_init (&ctx->events);
72-
ctx->test_framework_uri = test_framework_get_uri ();
73+
74+
ctx->test_framework_uri = mongoc_uri_copy (client->uri);
7375
ctx->acknowledged = true;
7476
ctx->verbose = test_framework_getenv_bool ("MONGOC_TEST_MONITORING_VERBOSE");
7577
bson_init (&ctx->lsids[0]);
@@ -347,6 +349,8 @@ error_code_from_name (const char *name)
347349
return 79;
348350
} else if (!strcmp (name, "UnsatisfiableWriteConcern")) {
349351
return 100;
352+
} else if (!strcmp (name, "OperationNotSupportedInTransaction")) {
353+
return 263;
350354
}
351355

352356
test_error ("Add errorCodeName \"%s\" to error_code_from_name()", name);

src/libmongoc/tests/json-test.c

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ get_bson_from_json_file (char *filename)
629629
}
630630

631631
static bool
632-
check_version_info (const bson_t *scenario)
632+
check_version_info (const bson_t *scenario, bool print_reason)
633633
{
634634
const char *s;
635635
char *padded;
@@ -643,7 +643,7 @@ check_version_info (const bson_t *scenario)
643643
bson_free (padded);
644644
server_version = test_framework_get_server_version ();
645645
if (server_version > test_version) {
646-
if (test_suite_debug_output ()) {
646+
if (print_reason && test_suite_debug_output ()) {
647647
printf (" SKIP, maxServerVersion=\"%s\"\n", s);
648648
fflush (stdout);
649649
}
@@ -657,7 +657,7 @@ check_version_info (const bson_t *scenario)
657657
test_version = test_framework_str_to_version (s);
658658
server_version = test_framework_get_server_version ();
659659
if (server_version < test_version) {
660-
if (test_suite_debug_output ()) {
660+
if (print_reason && test_suite_debug_output ()) {
661661
printf (" SKIP, minServerVersion=\"%s\"\n", s);
662662
fflush (stdout);
663663
}
@@ -698,8 +698,11 @@ check_version_info (const bson_t *scenario)
698698
}
699699

700700
/* If we didn't match any of the listed topologies, skip */
701-
printf (" SKIP, test topologies do not match current %s setup\n",
702-
current_topology);
701+
if (print_reason && test_suite_debug_output ()) {
702+
printf (" SKIP, test topologies do not match current %s setup\n",
703+
current_topology);
704+
fflush (stdout);
705+
}
703706

704707
return false;
705708
}
@@ -721,15 +724,20 @@ check_scenario_version (const bson_t *scenario)
721724

722725
while (bson_iter_next (&iter)) {
723726
bson_iter_bson (&iter, &version_info);
724-
if (check_version_info (&version_info)) {
727+
if (check_version_info (&version_info, false)) {
725728
return true;
726729
}
727730
}
728731

732+
if (test_suite_debug_output ()) {
733+
printf (" SKIP, no matching topologies in runOn\n");
734+
fflush (stdout);
735+
}
736+
729737
return false;
730738
}
731739

732-
return check_version_info (scenario);
740+
return check_version_info (scenario, true);
733741
}
734742

735743

@@ -989,17 +997,18 @@ execute_test (const json_test_config_t *config,
989997
collection->client->topology, MONGOC_SS_WRITE, NULL, &error);
990998
ASSERT_OR_PRINT (server_id, error);
991999

992-
if (bson_has_field (test, "failPoint")) {
993-
activate_fail_point (client, server_id, test, "failPoint");
994-
}
995-
9961000
json_test_ctx_init (&ctx, test, client, db, collection, config);
997-
set_apm_callbacks (&ctx, collection->client);
9981001

9991002
if (config->before_test_cb) {
10001003
config->before_test_cb (&ctx, test);
10011004
}
10021005

1006+
if (bson_has_field (test, "failPoint")) {
1007+
activate_fail_point (client, server_id, test, "failPoint");
1008+
}
1009+
1010+
set_apm_callbacks (&ctx, collection->client);
1011+
10031012
json_test_operations (&ctx, test);
10041013

10051014
if (config->after_test_cb) {
@@ -1138,6 +1147,9 @@ set_uri_opts_from_bson (mongoc_uri_t *uri, const bson_t *opts)
11381147
} else if (!strcmp (bson_iter_key (&iter), "retryWrites")) {
11391148
mongoc_uri_set_option_as_bool (
11401149
uri, "retryWrites", bson_iter_bool (&iter));
1150+
} else if (!strcmp (bson_iter_key (&iter), "heartbeatFrequencyMS")) {
1151+
mongoc_uri_set_option_as_int32 (
1152+
uri, "heartbeatFrequencyMS", bson_iter_int32 (&iter));
11411153
} else {
11421154
MONGOC_ERROR ("Unsupported clientOptions field \"%s\" in %s",
11431155
bson_iter_key (&iter),
@@ -1148,6 +1160,44 @@ set_uri_opts_from_bson (mongoc_uri_t *uri, const bson_t *opts)
11481160
}
11491161

11501162

1163+
static bool
1164+
_should_skip_due_to_server_39704 (const bson_t *test)
1165+
{
1166+
const char *desc = bson_lookup_utf8 (test, "description");
1167+
const char *bad_tests[] = {
1168+
"only first countDocuments includes readConcern",
1169+
"only first find includes readConcern",
1170+
"only first aggregate includes readConcern",
1171+
"only first distinct includes readConcern",
1172+
"only first runCommand includes readConcern",
1173+
"transaction options inherited from defaultTransactionOptions",
1174+
"startTransaction options override defaults",
1175+
"defaultTransactionOptions override client options",
1176+
"readConcern snapshot in startTransaction options",
1177+
"withTransaction inherits transaction options from "
1178+
"defaultTransactionOptions",
1179+
"withTransaction explicit transaction options",
1180+
"withTransaction explicit transaction options override "
1181+
"defaultTransactionOptions",
1182+
"withTransaction explicit transaction options override client options"};
1183+
int i;
1184+
1185+
/* Only an issue for sharded clusters. */
1186+
if (!test_framework_is_mongos ()) {
1187+
return false;
1188+
}
1189+
1190+
for (i = 0; i < sizeof (bad_tests) / sizeof (char *); i++) {
1191+
if (0 == strcmp (desc, bad_tests[i])) {
1192+
return true;
1193+
}
1194+
}
1195+
1196+
1197+
return false;
1198+
}
1199+
1200+
11511201
/*
11521202
*-----------------------------------------------------------------------
11531203
*
@@ -1221,13 +1271,22 @@ run_json_general_test (const json_test_config_t *config)
12211271
continue;
12221272
}
12231273

1274+
if (_should_skip_due_to_server_39704 (&test)) {
1275+
fprintf (stderr,
1276+
" - %s SKIPPED, reason: SERVER-39704 causes sharded tests to "
1277+
"fail when using readConcern: snapshot\n",
1278+
description);
1279+
continue;
1280+
}
1281+
12241282
bson_free (selected_test);
12251283

12261284
uri = test_framework_get_uri ();
12271285

1228-
/* If we are using multiple mongos, hardcode them in, for now,
1229-
but keep the other URI components (CDRIVER-3285) */
1230-
if (bson_iter_init_find (&uri_iter, &test, "useMultipleMongoses")) {
1286+
/* If we are using multiple mongos, hardcode them in, for now, but keep
1287+
* the other URI components (CDRIVER-3285) */
1288+
if (bson_iter_init_find (&uri_iter, &test, "useMultipleMongoses") &&
1289+
bson_iter_as_bool (&uri_iter)) {
12311290
ASSERT_OR_PRINT (
12321291
mongoc_uri_upsert_host_and_port (uri, "localhost:27017", &error),
12331292
error);

src/libmongoc/tests/json/transactions/abort.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
{
2-
"topology": [
3-
"replicaset",
4-
"sharded"
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.0",
5+
"topology": [
6+
"replicaset"
7+
]
8+
},
9+
{
10+
"minServerVersion": "4.1.8",
11+
"topology": [
12+
"sharded"
13+
]
14+
}
515
],
616
"database_name": "transaction-tests",
717
"collection_name": "test",

src/libmongoc/tests/json/transactions/bulk.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
{
2-
"topology": [
3-
"replicaset",
4-
"sharded"
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.0",
5+
"topology": [
6+
"replicaset"
7+
]
8+
},
9+
{
10+
"minServerVersion": "4.1.8",
11+
"topology": [
12+
"sharded"
13+
]
14+
}
515
],
616
"database_name": "transaction-tests",
717
"collection_name": "test",

src/libmongoc/tests/json/transactions/causal-consistency.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
{
2-
"topology": [
3-
"replicaset",
4-
"sharded"
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.0",
5+
"topology": [
6+
"replicaset"
7+
]
8+
},
9+
{
10+
"minServerVersion": "4.1.8",
11+
"topology": [
12+
"sharded"
13+
]
14+
}
515
],
616
"database_name": "transaction-tests",
717
"collection_name": "test",

src/libmongoc/tests/json/transactions/commit.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
{
2-
"topology": [
3-
"replicaset",
4-
"sharded"
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.0",
5+
"topology": [
6+
"replicaset"
7+
]
8+
},
9+
{
10+
"minServerVersion": "4.1.8",
11+
"topology": [
12+
"sharded"
13+
]
14+
}
515
],
616
"database_name": "transaction-tests",
717
"collection_name": "test",

0 commit comments

Comments
 (0)