Skip to content

Commit 16e2748

Browse files
authored
CDRIVER-4341 unskip /Stepdown/not_primary_keep (#1427)
* unskip `/Stepdown/not_primary_keep` * add reference to specification * separate `/Stepdown` tests into `/pooled` and `/single` This may help to narrow down a test failure. A failing assert does not identify whether a pooled client was used. * use macro to reduce repetition
1 parent 843fd5f commit 16e2748

File tree

2 files changed

+72
-72
lines changed

2 files changed

+72
-72
lines changed

.evergreen/etc/skip-tests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
/mongohouse/listDatabases # CDRIVER-4333
2828
/mongohouse/runCommand # CDRIVER-4333
2929

30-
/Stepdown/not_primary_keep # (CDRIVER-4341) Assert Failure: 673 == 674
3130
/change_stream/live/track_resume_token # (CDRIVER-4344) Condition 'bson_compare (resume_token, &doc2_rt) == 0' failed
3231
/BulkOperation/split # (CDRIVER-4346) Assert Failure: count of split_1512376901_50824 is 97759, not 100010
3332
/ClientPool/pop_timeout # (CDRIVER-4348) precondition failed: duration_usec / 1000 >= 1990

src/libmongoc/tests/test-mongoc-primary-stepdown.c

Lines changed: 72 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// test-mongoc-primary-stepdown.c contains tests specified in:
2+
// `Connections Survive Primary Step Down Tests`. See:
3+
// https://github.com/mongodb/specifications/tree/db3114e957f7c0976a1af09882dbb46cb4a70049/source/connections-survive-step-down/tests
4+
15
#include "mongoc/mongoc.h"
26
#include "mongoc/mongoc-read-concern-private.h"
37
#include "mongoc/mongoc-util-private.h"
@@ -9,6 +13,11 @@
913
#include "test-conveniences.h"
1014
#include "test-libmongoc.h"
1115

16+
typedef struct {
17+
// If `use_pooled` is true, a test is run with a `mongoc_client_t` obtained
18+
// from a `mongoc_client_pool_t`.
19+
bool use_pooled;
20+
} test_ctx_t;
1221

1322
static mongoc_uri_t *
1423
_get_test_uri (void)
@@ -90,32 +99,34 @@ _connection_count (mongoc_client_t *client, uint32_t server_id)
9099
typedef void (*_test_fn_t) (mongoc_client_t *);
91100

92101
static void
93-
_run_test_single_and_pooled (_test_fn_t test)
102+
_run_test_single_or_pooled (_test_fn_t test, bool use_pooled)
94103
{
95104
mongoc_uri_t *uri;
96105
mongoc_client_t *client;
97106
mongoc_client_pool_t *pool;
98107

99108
uri = _get_test_uri ();
100109

101-
/* Run in single-threaded mode */
102-
client = test_framework_client_new_from_uri (uri, NULL);
103-
test_framework_set_ssl_opts (client);
104-
_setup_test_with_client (client);
105-
test (client);
106-
mongoc_client_destroy (client);
107-
108-
/* Run in pooled mode */
109-
pool = test_framework_client_pool_new_from_uri (uri, NULL);
110-
test_framework_set_pool_ssl_opts (pool);
111-
client = mongoc_client_pool_pop (pool);
112-
_setup_test_with_client (client);
113-
/* Wait one second to be assured that the RTT connection has been established
114-
* as well. */
115-
_mongoc_usleep (1000 * 1000);
116-
test (client);
117-
mongoc_client_pool_push (pool, client);
118-
mongoc_client_pool_destroy (pool);
110+
if (!use_pooled) {
111+
/* Run in single-threaded mode */
112+
client = test_framework_client_new_from_uri (uri, NULL);
113+
test_framework_set_ssl_opts (client);
114+
_setup_test_with_client (client);
115+
test (client);
116+
mongoc_client_destroy (client);
117+
} else {
118+
/* Run in pooled mode */
119+
pool = test_framework_client_pool_new_from_uri (uri, NULL);
120+
test_framework_set_pool_ssl_opts (pool);
121+
client = mongoc_client_pool_pop (pool);
122+
_setup_test_with_client (client);
123+
/* Wait one second to be assured that the RTT connection has been
124+
* established as well. */
125+
_mongoc_usleep (1000 * 1000);
126+
test (client);
127+
mongoc_client_pool_push (pool, client);
128+
mongoc_client_pool_destroy (pool);
129+
}
119130

120131
mongoc_uri_destroy (uri);
121132
}
@@ -201,16 +212,16 @@ test_getmore_iteration (mongoc_client_t *client)
201212
}
202213

203214
static void
204-
test_getmore_iteration_runner (void *ctx)
215+
test_getmore_iteration_runner (void *ctx_void)
205216
{
206-
BSON_UNUSED (ctx);
217+
test_ctx_t *ctx = ctx_void;
207218

208219
/* Only run on 4.2 or higher */
209220
if (!test_framework_max_wire_version_at_least (8)) {
210221
return;
211222
}
212223

213-
_run_test_single_and_pooled (test_getmore_iteration);
224+
_run_test_single_or_pooled (test_getmore_iteration, ctx->use_pooled);
214225
}
215226

216227
static void
@@ -272,16 +283,16 @@ test_not_primary_keep_pool (mongoc_client_t *client)
272283
}
273284

274285
static void
275-
test_not_primary_keep_pool_runner (void *ctx)
286+
test_not_primary_keep_pool_runner (void *ctx_void)
276287
{
277-
BSON_UNUSED (ctx);
288+
test_ctx_t *ctx = ctx_void;
278289

279290
/* Only run on 4.2 and higher */
280291
if (!test_framework_max_wire_version_at_least (8)) {
281292
return;
282293
}
283294

284-
_run_test_single_and_pooled (test_not_primary_keep_pool);
295+
_run_test_single_or_pooled (test_not_primary_keep_pool, ctx->use_pooled);
285296
}
286297

287298
static void
@@ -346,19 +357,19 @@ test_not_primary_reset_pool (mongoc_client_t *client)
346357
}
347358

348359
static void
349-
test_not_primary_reset_pool_runner (void *ctx)
360+
test_not_primary_reset_pool_runner (void *ctx_void)
350361
{
351362
int64_t max_wire_version;
352363

353-
BSON_UNUSED (ctx);
364+
test_ctx_t *ctx = ctx_void;
354365

355366
/* Only run if version 4.0 */
356367
test_framework_get_max_wire_version (&max_wire_version);
357368
if (max_wire_version != WIRE_VERSION_4_0) {
358369
return;
359370
}
360371

361-
_run_test_single_and_pooled (test_not_primary_reset_pool);
372+
_run_test_single_or_pooled (test_not_primary_reset_pool, ctx->use_pooled);
362373
}
363374

364375
static void
@@ -420,16 +431,16 @@ test_shutdown_reset_pool (mongoc_client_t *client)
420431
}
421432

422433
static void
423-
test_shutdown_reset_pool_runner (void *ctx)
434+
test_shutdown_reset_pool_runner (void *ctx_void)
424435
{
425-
BSON_UNUSED (ctx);
436+
test_ctx_t *ctx = ctx_void;
426437

427438
/* Only run if version >= 4.0 */
428439
if (!test_framework_max_wire_version_at_least (WIRE_VERSION_4_0)) {
429440
return;
430441
}
431442

432-
_run_test_single_and_pooled (test_shutdown_reset_pool);
443+
_run_test_single_or_pooled (test_shutdown_reset_pool, ctx->use_pooled);
433444
}
434445

435446
static void
@@ -491,58 +502,48 @@ test_interrupted_shutdown_reset_pool (mongoc_client_t *client)
491502
}
492503

493504
static void
494-
test_interrupted_shutdown_reset_pool_runner (void *ctx)
505+
test_interrupted_shutdown_reset_pool_runner (void *ctx_void)
495506
{
496-
BSON_UNUSED (ctx);
507+
test_ctx_t *ctx = ctx_void;
497508

498509
/* Only run if version >= 4.0 */
499510
if (!test_framework_max_wire_version_at_least (WIRE_VERSION_4_0)) {
500511
return;
501512
}
502513

503-
_run_test_single_and_pooled (test_interrupted_shutdown_reset_pool);
514+
_run_test_single_or_pooled (test_interrupted_shutdown_reset_pool,
515+
ctx->use_pooled);
504516
}
505517

506518
void
507519
test_primary_stepdown_install (TestSuite *suite)
508520
{
509-
TestSuite_AddFull (suite,
510-
"/Stepdown/getmore",
511-
test_getmore_iteration_runner,
512-
NULL,
513-
NULL,
514-
test_framework_skip_if_auth,
521+
test_ctx_t single_ctx = {.use_pooled = false};
522+
test_ctx_t pooled_ctx = {.use_pooled = true};
523+
524+
#define TestPooledAndSingle(name, fn) \
525+
TestSuite_AddFull (suite, \
526+
name "/single", \
527+
fn, \
528+
NULL, \
529+
&single_ctx, \
530+
test_framework_skip_if_auth, \
531+
test_framework_skip_if_not_replset); \
532+
TestSuite_AddFull (suite, \
533+
name "/pooled", \
534+
fn, \
535+
NULL, \
536+
&pooled_ctx, \
537+
test_framework_skip_if_auth, \
515538
test_framework_skip_if_not_replset);
516539

517-
TestSuite_AddFull (suite,
518-
"/Stepdown/not_primary_keep",
519-
test_not_primary_keep_pool_runner,
520-
NULL,
521-
NULL,
522-
test_framework_skip_if_auth,
523-
test_framework_skip_if_not_replset);
524-
525-
TestSuite_AddFull (suite,
526-
"/Stepdown/not_primary_reset",
527-
test_not_primary_reset_pool_runner,
528-
NULL,
529-
NULL,
530-
test_framework_skip_if_auth,
531-
test_framework_skip_if_not_replset);
532-
533-
TestSuite_AddFull (suite,
534-
"/Stepdown/shutdown_reset_pool",
535-
test_shutdown_reset_pool_runner,
536-
NULL,
537-
NULL,
538-
test_framework_skip_if_auth,
539-
test_framework_skip_if_not_replset);
540-
541-
TestSuite_AddFull (suite,
542-
"/Stepdown/interrupt_shutdown",
543-
test_interrupted_shutdown_reset_pool_runner,
544-
NULL,
545-
NULL,
546-
test_framework_skip_if_auth,
547-
test_framework_skip_if_not_replset);
540+
TestPooledAndSingle ("/Stepdown/getmore", test_getmore_iteration_runner);
541+
TestPooledAndSingle ("/Stepdown/not_primary_keep",
542+
test_not_primary_keep_pool_runner);
543+
TestPooledAndSingle ("/Stepdown/not_primary_reset",
544+
test_not_primary_reset_pool_runner);
545+
TestPooledAndSingle ("/Stepdown/shutdown_reset_pool",
546+
test_shutdown_reset_pool_runner);
547+
TestPooledAndSingle ("/Stepdown/interrupt_shutdown",
548+
test_interrupted_shutdown_reset_pool_runner);
548549
}

0 commit comments

Comments
 (0)