Skip to content

Commit a3558fe

Browse files
committed
CDRIVER-2329 race in topology test
1 parent 0ed1330 commit a3558fe

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tests/test-mongoc-topology.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ _test_topology_invalidate_server (bool pooled)
285285
mongoc_server_description_t *fake_sd;
286286
mongoc_server_description_t *sd;
287287
mongoc_topology_description_t *td;
288+
mongoc_uri_t *uri;
288289
mongoc_client_t *client;
289290
mongoc_client_pool_t *pool = NULL;
290291
bson_error_t error;
@@ -293,14 +294,18 @@ _test_topology_invalidate_server (bool pooled)
293294
uint32_t id;
294295
mongoc_server_stream_t *server_stream;
295296

297+
uri = test_framework_get_uri ();
298+
/* no auto heartbeat */
299+
mongoc_uri_set_option_as_int32 (uri, "heartbeatFrequencyMS", INT32_MAX);
300+
296301
if (pooled) {
297-
pool = test_framework_client_pool_new ();
302+
pool = mongoc_client_pool_new (uri);
298303
client = mongoc_client_pool_pop (pool);
299304

300305
/* background scanner complains about failed connection */
301306
capture_logs (true);
302307
} else {
303-
client = test_framework_client_new ();
308+
client = mongoc_client_new_from_uri (uri);
304309
}
305310

306311
td = &client->topology->description;
@@ -309,9 +314,8 @@ _test_topology_invalidate_server (bool pooled)
309314
server_stream =
310315
mongoc_cluster_stream_for_reads (&client->cluster, NULL, &error);
311316
ASSERT_OR_PRINT (server_stream, error);
317+
sd = server_stream->sd;
312318
id = server_stream->sd->id;
313-
sd = (mongoc_server_description_t *) mongoc_set_get (td->servers, id);
314-
BSON_ASSERT (sd);
315319
BSON_ASSERT (sd->type == MONGOC_SERVER_STANDALONE ||
316320
sd->type == MONGOC_SERVER_RS_PRIMARY ||
317321
sd->type == MONGOC_SERVER_MONGOS);
@@ -340,6 +344,7 @@ _test_topology_invalidate_server (bool pooled)
340344
client->topology->scanner, &fake_host_list, fake_id);
341345
BSON_ASSERT (!mongoc_cluster_stream_for_server (
342346
&client->cluster, fake_id, true, &error));
347+
mongoc_mutex_lock (&client->topology->mutex);
343348
sd = (mongoc_server_description_t *) mongoc_set_get (td->servers, fake_id);
344349
BSON_ASSERT (sd);
345350
BSON_ASSERT (sd->type == MONGOC_SERVER_UNKNOWN);
@@ -350,8 +355,10 @@ _test_topology_invalidate_server (bool pooled)
350355
BSON_ASSERT (bson_empty (&sd->passives));
351356
BSON_ASSERT (bson_empty (&sd->arbiters));
352357
BSON_ASSERT (bson_empty (&sd->compressors));
358+
mongoc_mutex_unlock (&client->topology->mutex);
353359

354360
mongoc_server_stream_cleanup (server_stream);
361+
mongoc_uri_destroy (uri);
355362

356363
if (pooled) {
357364
mongoc_client_pool_push (pool, client);

0 commit comments

Comments
 (0)