Skip to content

Commit 7f69906

Browse files
authored
CPP-709 - Stabilize chaotic session unit tests (#212)
1 parent 1838a04 commit 7f69906

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

cpp-driver/gtests/src/unit/tests/test_session.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ class SessionUnitTest : public EventLoopTest {
6666

6767
static void connect(cass::Session* session,
6868
cass::SslContext* ssl_context = NULL,
69-
uint64_t wait_for_time_us = WAIT_FOR_TIME) {
69+
uint64_t wait_for_time_us = WAIT_FOR_TIME,
70+
size_t num_nodes = 3) {
7071
cass::Config config;
7172
config.set_reconnect_wait_time(100); // Faster reconnect time to handle cluster starts and stops
72-
config.contact_points().push_back("127.0.0.1");
73-
config.contact_points().push_back("127.0.0.2"); // Handle three node clusters (for chaotic scenarios)
74-
config.contact_points().push_back("127.0.0.3");
73+
for (size_t i = 1; i <= num_nodes; ++i) {
74+
cass::OStringStream ss;
75+
ss << "127.0.0." << i;
76+
config.contact_points().push_back(ss.str());
77+
}
7578
if (ssl_context) {
7679
config.set_ssl_context(ssl_context);
7780
}
@@ -306,7 +309,7 @@ TEST_F(SessionUnitTest, ExecuteQueryReusingSessionUsingSsl) {
306309
}
307310

308311
TEST_F(SessionUnitTest, ExecuteQueryReusingSessionChaotic) {
309-
mockssandra::SimpleCluster cluster(simple(), 3);
312+
mockssandra::SimpleCluster cluster(simple(), 4);
310313
ASSERT_EQ(cluster.start_all(), 0);
311314

312315
OutagePlan outage_plan(loop(), &cluster);
@@ -315,14 +318,14 @@ TEST_F(SessionUnitTest, ExecuteQueryReusingSessionChaotic) {
315318
cass::Session session;
316319
cass::Future::Ptr outage_future = execute_outage_plan(&outage_plan);
317320
while (!outage_future->wait_for(1000)) { // 1 millisecond wait
318-
connect(&session, NULL, WAIT_FOR_TIME * 3);
321+
connect(&session, NULL, WAIT_FOR_TIME * 3, 4);
319322
query(&session);
320323
close(&session, WAIT_FOR_TIME * 3);
321324
}
322325
}
323326

324327
TEST_F(SessionUnitTest, ExecuteQueryReusingSessionUsingSslChaotic) {
325-
mockssandra::SimpleCluster cluster(simple(), 3);
328+
mockssandra::SimpleCluster cluster(simple(), 4);
326329
cass::SslContext::Ptr ssl_context = use_ssl(&cluster).socket_settings.ssl_context;
327330
ASSERT_EQ(cluster.start_all(), 0);
328331

@@ -332,7 +335,7 @@ TEST_F(SessionUnitTest, ExecuteQueryReusingSessionUsingSslChaotic) {
332335
cass::Session session;
333336
cass::Future::Ptr outage_future = execute_outage_plan(&outage_plan);
334337
while (!outage_future->wait_for(1000)) { // 1 millisecond wait
335-
connect(&session, ssl_context.get(), WAIT_FOR_TIME * 3);
338+
connect(&session, ssl_context.get(), WAIT_FOR_TIME * 3, 4);
336339
query(&session);
337340
close(&session, WAIT_FOR_TIME * 3);
338341
}
@@ -413,7 +416,7 @@ TEST_F(SessionUnitTest, ExecuteQueryWithThreadsUsingSsl) {
413416
}
414417

415418
TEST_F(SessionUnitTest, ExecuteQueryWithThreadsChaotic) {
416-
mockssandra::SimpleCluster cluster(simple(), 3);
419+
mockssandra::SimpleCluster cluster(simple(), 4);
417420
ASSERT_EQ(cluster.start_all(), 0);
418421

419422
cass::Session session;
@@ -431,7 +434,7 @@ TEST_F(SessionUnitTest, ExecuteQueryWithThreadsChaotic) {
431434
}
432435

433436
TEST_F(SessionUnitTest, ExecuteQueryWithThreadsUsingSslChaotic) {
434-
mockssandra::SimpleCluster cluster(simple(), 3);
437+
mockssandra::SimpleCluster cluster(simple(), 4);
435438
cass::SslContext::Ptr ssl_context = use_ssl(&cluster).socket_settings.ssl_context;
436439
ASSERT_EQ(cluster.start_all(), 0);
437440

0 commit comments

Comments
 (0)