Skip to content

Commit 1796159

Browse files
authored
CPP-806 Fix handling of no contact points (#280)
1 parent 8dfc597 commit 1796159

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,3 +957,20 @@ TEST_F(ClusterUnitTest, ReconnectionPolicy) {
957957
EXPECT_GE(policy->scheduled_delay_count(), 2u);
958958
EXPECT_EQ(3u, mock_cluster.connection_attempts(1)); // Includes initial connection attempt
959959
}
960+
961+
TEST_F(ClusterUnitTest, NoContactPoints) {
962+
// No cluster needed
963+
964+
AddressVec contact_points; // Empty
965+
966+
Future::Ptr connect_future(new Future());
967+
ClusterConnector::Ptr connector(
968+
new ClusterConnector(contact_points, PROTOCOL_VERSION,
969+
bind_callback(on_connection_connected, connect_future.get())));
970+
connector->connect(event_loop());
971+
972+
ASSERT_TRUE(connect_future->wait_for(WAIT_FOR_TIME))
973+
<< "Timed out waiting for cluster to connect";
974+
ASSERT_TRUE(connect_future->error());
975+
EXPECT_EQ(connect_future->error()->code, CASS_ERROR_LIB_NO_HOSTS_AVAILABLE);
976+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,3 +610,17 @@ TEST_F(SessionUnitTest, HostListenerNodeDown) {
610610

611611
ASSERT_EQ(0u, listener->event_count());
612612
}
613+
614+
TEST_F(SessionUnitTest, NoContactPoints) {
615+
// No cluster needed
616+
617+
Config config;
618+
config.contact_points().clear();
619+
620+
Session session;
621+
Future::Ptr connect_future(session.connect(config));
622+
ASSERT_TRUE(connect_future->wait_for(WAIT_FOR_TIME))
623+
<< "Timed out waiting for session to connect";
624+
ASSERT_TRUE(connect_future->error());
625+
EXPECT_EQ(connect_future->error()->code, CASS_ERROR_LIB_NO_HOSTS_AVAILABLE);
626+
}

cpp-driver/src/cluster_connector.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ Cluster::Ptr ClusterConnector::release_cluster() {
104104
void ClusterConnector::internal_resolve_and_connect() {
105105
inc_ref();
106106

107-
assert(!contact_points_.empty() && "Contact points should never be empty");
108-
109-
if (random_) {
107+
if (random_ && !contact_points_.empty()) {
110108
random_shuffle(contact_points_.begin(), contact_points_.end(), random_);
111109
}
112110

0 commit comments

Comments
 (0)