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
This commit is contained in:
Chris Dent 2015-08-07 17:20:02 +00:00
parent a68448b975
commit 00aa6cec3e

View File

@ -54,15 +54,17 @@ class ConnectionRetryTest(base.BaseTestCase):
self.CONF = self.useFixture(fixture_config.Config()).conf self.CONF = self.useFixture(fixture_config.Config()).conf
def test_retries(self): 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: try:
self.CONF.set_override("connection", "no-such-engine://", self.CONF.set_override("connection", "no-such-engine://",
group="database") group="database")
self.CONF.set_override("retry_interval", 0.00001,
group="database")
storage.get_connection_from_config(self.CONF) storage.get_connection_from_config(self.CONF)
except RuntimeError as err: except RuntimeError as err:
self.assertIn('no-such-engine', six.text_type(err)) self.assertIn('no-such-engine', six.text_type(err))
self.assertEqual(9, retry_sleep.call_count) self.assertEqual(10, retry_reject.call_count)
retry_sleep.assert_called_with(10.0)
class ConnectionConfigTest(base.BaseTestCase): class ConnectionConfigTest(base.BaseTestCase):