Skip to content

CDRIVER-4341 unskip /Stepdown/not_primary_keep #1427

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

Merged
merged 5 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .evergreen/etc/skip-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
/mongohouse/listDatabases # CDRIVER-4333
/mongohouse/runCommand # CDRIVER-4333

/Stepdown/not_primary_keep # (CDRIVER-4341) Assert Failure: 673 == 674
/change_stream/live/track_resume_token # (CDRIVER-4344) Condition 'bson_compare (resume_token, &doc2_rt) == 0' failed
/BulkOperation/split # (CDRIVER-4346) Assert Failure: count of split_1512376901_50824 is 97759, not 100010
/ClientPool/pop_timeout # (CDRIVER-4348) precondition failed: duration_usec / 1000 >= 1990
Expand Down
143 changes: 72 additions & 71 deletions src/libmongoc/tests/test-mongoc-primary-stepdown.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// test-mongoc-primary-stepdown.c contains tests specified in:
// `Connections Survive Primary Step Down Tests`. See:
// https://github.com/mongodb/specifications/tree/db3114e957f7c0976a1af09882dbb46cb4a70049/source/connections-survive-step-down/tests

#include "mongoc/mongoc.h"
#include "mongoc/mongoc-read-concern-private.h"
#include "mongoc/mongoc-util-private.h"
Expand All @@ -9,6 +13,11 @@
#include "test-conveniences.h"
#include "test-libmongoc.h"

typedef struct {
// If `use_pooled` is true, a test is run with a `mongoc_client_t` obtained
// from a `mongoc_client_pool_t`.
bool use_pooled;
} test_ctx_t;

static mongoc_uri_t *
_get_test_uri (void)
Expand Down Expand Up @@ -90,32 +99,34 @@ _connection_count (mongoc_client_t *client, uint32_t server_id)
typedef void (*_test_fn_t) (mongoc_client_t *);

static void
_run_test_single_and_pooled (_test_fn_t test)
_run_test_single_or_pooled (_test_fn_t test, bool use_pooled)
{
mongoc_uri_t *uri;
mongoc_client_t *client;
mongoc_client_pool_t *pool;

uri = _get_test_uri ();

/* Run in single-threaded mode */
client = test_framework_client_new_from_uri (uri, NULL);
test_framework_set_ssl_opts (client);
_setup_test_with_client (client);
test (client);
mongoc_client_destroy (client);

/* Run in pooled mode */
pool = test_framework_client_pool_new_from_uri (uri, NULL);
test_framework_set_pool_ssl_opts (pool);
client = mongoc_client_pool_pop (pool);
_setup_test_with_client (client);
/* Wait one second to be assured that the RTT connection has been established
* as well. */
_mongoc_usleep (1000 * 1000);
test (client);
mongoc_client_pool_push (pool, client);
mongoc_client_pool_destroy (pool);
if (!use_pooled) {
/* Run in single-threaded mode */
client = test_framework_client_new_from_uri (uri, NULL);
test_framework_set_ssl_opts (client);
_setup_test_with_client (client);
test (client);
mongoc_client_destroy (client);
} else {
/* Run in pooled mode */
pool = test_framework_client_pool_new_from_uri (uri, NULL);
test_framework_set_pool_ssl_opts (pool);
client = mongoc_client_pool_pop (pool);
_setup_test_with_client (client);
/* Wait one second to be assured that the RTT connection has been
* established as well. */
_mongoc_usleep (1000 * 1000);
test (client);
mongoc_client_pool_push (pool, client);
mongoc_client_pool_destroy (pool);
}

mongoc_uri_destroy (uri);
}
Expand Down Expand Up @@ -201,16 +212,16 @@ test_getmore_iteration (mongoc_client_t *client)
}

static void
test_getmore_iteration_runner (void *ctx)
test_getmore_iteration_runner (void *ctx_void)
{
BSON_UNUSED (ctx);
test_ctx_t *ctx = ctx_void;

/* Only run on 4.2 or higher */
if (!test_framework_max_wire_version_at_least (8)) {
return;
}

_run_test_single_and_pooled (test_getmore_iteration);
_run_test_single_or_pooled (test_getmore_iteration, ctx->use_pooled);
}

static void
Expand Down Expand Up @@ -272,16 +283,16 @@ test_not_primary_keep_pool (mongoc_client_t *client)
}

static void
test_not_primary_keep_pool_runner (void *ctx)
test_not_primary_keep_pool_runner (void *ctx_void)
{
BSON_UNUSED (ctx);
test_ctx_t *ctx = ctx_void;

/* Only run on 4.2 and higher */
if (!test_framework_max_wire_version_at_least (8)) {
return;
}

_run_test_single_and_pooled (test_not_primary_keep_pool);
_run_test_single_or_pooled (test_not_primary_keep_pool, ctx->use_pooled);
}

static void
Expand Down Expand Up @@ -346,19 +357,19 @@ test_not_primary_reset_pool (mongoc_client_t *client)
}

static void
test_not_primary_reset_pool_runner (void *ctx)
test_not_primary_reset_pool_runner (void *ctx_void)
{
int64_t max_wire_version;

BSON_UNUSED (ctx);
test_ctx_t *ctx = ctx_void;

/* Only run if version 4.0 */
test_framework_get_max_wire_version (&max_wire_version);
if (max_wire_version != WIRE_VERSION_4_0) {
return;
}

_run_test_single_and_pooled (test_not_primary_reset_pool);
_run_test_single_or_pooled (test_not_primary_reset_pool, ctx->use_pooled);
}

static void
Expand Down Expand Up @@ -420,16 +431,16 @@ test_shutdown_reset_pool (mongoc_client_t *client)
}

static void
test_shutdown_reset_pool_runner (void *ctx)
test_shutdown_reset_pool_runner (void *ctx_void)
{
BSON_UNUSED (ctx);
test_ctx_t *ctx = ctx_void;

/* Only run if version >= 4.0 */
if (!test_framework_max_wire_version_at_least (WIRE_VERSION_4_0)) {
return;
}

_run_test_single_and_pooled (test_shutdown_reset_pool);
_run_test_single_or_pooled (test_shutdown_reset_pool, ctx->use_pooled);
}

static void
Expand Down Expand Up @@ -491,58 +502,48 @@ test_interrupted_shutdown_reset_pool (mongoc_client_t *client)
}

static void
test_interrupted_shutdown_reset_pool_runner (void *ctx)
test_interrupted_shutdown_reset_pool_runner (void *ctx_void)
{
BSON_UNUSED (ctx);
test_ctx_t *ctx = ctx_void;

/* Only run if version >= 4.0 */
if (!test_framework_max_wire_version_at_least (WIRE_VERSION_4_0)) {
return;
}

_run_test_single_and_pooled (test_interrupted_shutdown_reset_pool);
_run_test_single_or_pooled (test_interrupted_shutdown_reset_pool,
ctx->use_pooled);
}

void
test_primary_stepdown_install (TestSuite *suite)
{
TestSuite_AddFull (suite,
"/Stepdown/getmore",
test_getmore_iteration_runner,
NULL,
NULL,
test_framework_skip_if_auth,
test_ctx_t single_ctx = {.use_pooled = false};
test_ctx_t pooled_ctx = {.use_pooled = true};

#define TestPooledAndSingle(name, fn) \
TestSuite_AddFull (suite, \
name "/single", \
fn, \
NULL, \
&single_ctx, \
test_framework_skip_if_auth, \
test_framework_skip_if_not_replset); \
TestSuite_AddFull (suite, \
name "/pooled", \
fn, \
NULL, \
&pooled_ctx, \
test_framework_skip_if_auth, \
test_framework_skip_if_not_replset);

TestSuite_AddFull (suite,
"/Stepdown/not_primary_keep",
test_not_primary_keep_pool_runner,
NULL,
NULL,
test_framework_skip_if_auth,
test_framework_skip_if_not_replset);

TestSuite_AddFull (suite,
"/Stepdown/not_primary_reset",
test_not_primary_reset_pool_runner,
NULL,
NULL,
test_framework_skip_if_auth,
test_framework_skip_if_not_replset);

TestSuite_AddFull (suite,
"/Stepdown/shutdown_reset_pool",
test_shutdown_reset_pool_runner,
NULL,
NULL,
test_framework_skip_if_auth,
test_framework_skip_if_not_replset);

TestSuite_AddFull (suite,
"/Stepdown/interrupt_shutdown",
test_interrupted_shutdown_reset_pool_runner,
NULL,
NULL,
test_framework_skip_if_auth,
test_framework_skip_if_not_replset);
TestPooledAndSingle ("/Stepdown/getmore", test_getmore_iteration_runner);
TestPooledAndSingle ("/Stepdown/not_primary_keep",
test_not_primary_keep_pool_runner);
TestPooledAndSingle ("/Stepdown/not_primary_reset",
test_not_primary_reset_pool_runner);
TestPooledAndSingle ("/Stepdown/shutdown_reset_pool",
test_shutdown_reset_pool_runner);
TestPooledAndSingle ("/Stepdown/interrupt_shutdown",
test_interrupted_shutdown_reset_pool_runner);
}