From 00aa6cec3ec0c9725649ba3eaed9545a4076a28a Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Fri, 7 Aug 2015 17:20:02 +0000 Subject: [PATCH] Make ConnectionRetryTest more reliable The previous test relied on mocks of retrying.time.sleep. This is the same sleep as time.sleep so there's a chance, if eventlet is in context, that something else can call that. So instead the test now checks to see how many times should_reject is called. This is the same as the max retries that will be attempted. Also the retry wait time has been set to something very small so the test doesn't hang around sleeping uselessly, making test runs faster. Change-Id: Ib15d4d6f8dd23ba534d58005da5dc64aad9e0e90 Closes-Bug: #1482722 --- ceilometer/tests/unit/storage/test_get_connection.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ceilometer/tests/unit/storage/test_get_connection.py b/ceilometer/tests/unit/storage/test_get_connection.py index c47b83ac..6a7785a7 100644 --- a/ceilometer/tests/unit/storage/test_get_connection.py +++ b/ceilometer/tests/unit/storage/test_get_connection.py @@ -54,15 +54,17 @@ class ConnectionRetryTest(base.BaseTestCase): self.CONF = self.useFixture(fixture_config.Config()).conf def test_retries(self): - with mock.patch.object(retrying.time, 'sleep') as retry_sleep: + with mock.patch.object( + retrying.Retrying, 'should_reject') as retry_reject: try: self.CONF.set_override("connection", "no-such-engine://", group="database") + self.CONF.set_override("retry_interval", 0.00001, + group="database") storage.get_connection_from_config(self.CONF) except RuntimeError as err: self.assertIn('no-such-engine', six.text_type(err)) - self.assertEqual(9, retry_sleep.call_count) - retry_sleep.assert_called_with(10.0) + self.assertEqual(10, retry_reject.call_count) class ConnectionConfigTest(base.BaseTestCase):