From 18c31d673f7ee132ef4cc413d8fbdedb2e654b18 Mon Sep 17 00:00:00 2001 From: Adam Holmberg Date: Mon, 1 Dec 2014 18:52:56 +0000 Subject: [PATCH] Make test_refresh_schema_timeout test work previously a failed assertion in bad_wait_for_responses was causing the test to take an unexpected path, failing silently --- tests/unit/test_control_connection.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/unit/test_control_connection.py b/tests/unit/test_control_connection.py index 3ca2e816..12d09781 100644 --- a/tests/unit/test_control_connection.py +++ b/tests/unit/test_control_connection.py @@ -59,7 +59,7 @@ class MockMetadata(object): class MockCluster(object): - max_schema_agreement_wait = Cluster.max_schema_agreement_wait + max_schema_agreement_wait = 5 load_balancing_policy = RoundRobinPolicy() reconnection_policy = ConstantReconnectionPolicy(2) down_host = None @@ -131,7 +131,7 @@ class ControlConnectionTest(unittest.TestCase): self.connection = MockConnection() self.time = FakeTime() - self.control_connection = ControlConnection(self.cluster, timeout=0.01) + self.control_connection = ControlConnection(self.cluster, timeout=1) self.control_connection._connection = self.connection self.control_connection._time = self.time @@ -206,7 +206,7 @@ class ControlConnectionTest(unittest.TestCase): self.connection.peer_results[1][1][2] = 'b' self.assertFalse(self.control_connection.wait_for_schema_agreement()) # the control connection should have slept until it hit the limit - self.assertGreaterEqual(self.time.clock, Cluster.max_schema_agreement_wait) + self.assertGreaterEqual(self.time.clock, self.cluster.max_schema_agreement_wait) def test_wait_for_schema_agreement_skipping(self): """ @@ -247,7 +247,7 @@ class ControlConnectionTest(unittest.TestCase): # but once we mark it up, the control connection will care host.is_up = True self.assertFalse(self.control_connection.wait_for_schema_agreement()) - self.assertGreaterEqual(self.time.clock, Cluster.max_schema_agreement_wait) + self.assertGreaterEqual(self.time.clock, self.cluster.max_schema_agreement_wait) def test_refresh_nodes_and_tokens(self): self.control_connection.refresh_node_list_and_token_map() @@ -332,12 +332,13 @@ class ControlConnectionTest(unittest.TestCase): def test_refresh_schema_timeout(self): def bad_wait_for_responses(*args, **kwargs): - self.assertEqual(kwargs['timeout'], self.control_connection._timeout) + self.time.sleep(kwargs['timeout']) raise OperationTimedOut() - self.connection.wait_for_responses = bad_wait_for_responses + self.connection.wait_for_responses = Mock(side_effect=bad_wait_for_responses) self.control_connection.refresh_schema() - self.cluster.executor.submit.assert_called_with(self.control_connection._reconnect) + self.assertEqual(self.connection.wait_for_responses.call_count, self.cluster.max_schema_agreement_wait/self.control_connection._timeout) + self.assertEqual(self.connection.wait_for_responses.call_args[1]['timeout'], self.control_connection._timeout) def test_handle_topology_change(self): event = {