summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Podolyaka <rpodolyaka@mirantis.com>2013-06-20 14:15:35 +0300
committerRoman Podolyaka <rpodolyaka@mirantis.com>2013-06-26 14:47:17 +0300
commitd8942ecc632efb1f960d0bb225703e15783dcb7c (patch)
tree3503e46325b1eff3c312adaaa579e9b4b21a7dd7
parente9f567c8ed31d71002b7e3149aeea274e42b9321 (diff)
downloadoslo-d8942ecc632efb1f960d0bb225703e15783dcb7c.zip
oslo-d8942ecc632efb1f960d0bb225703e15783dcb7c.tar.gz
oslo-d8942ecc632efb1f960d0bb225703e15783dcb7c.tar.xz
Refactor KombuStubs fixture.
Fixes bug 1192924. Change-Id: Ic6d9715c945e620da20b43310e8e8ba79296e4ad
-rw-r--r--tests/unit/rpc/test_kombu.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/tests/unit/rpc/test_kombu.py b/tests/unit/rpc/test_kombu.py
index 54f8389..372b925 100644
--- a/tests/unit/rpc/test_kombu.py
+++ b/tests/unit/rpc/test_kombu.py
@@ -25,7 +25,9 @@ eventlet.monkey_patch()
import contextlib
import functools
import logging
+import weakref
+import fixtures
import mock
from oslo.config import cfg
import six
@@ -67,17 +69,24 @@ def _raise_exc_stub(stubs, times, obj, method, exc_msg,
return info
-class KombuStubs:
- @staticmethod
+class KombuStubs(fixtures.Fixture):
+ def __init__(self, test):
+ super(KombuStubs, self).__init__()
+
+ # NOTE(rpodolyaka): use a weak ref here to prevent ref cycles
+ self.test = weakref.ref(test)
+
def setUp(self):
+ super(KombuStubs, self).setUp()
+
+ test = self.test()
if kombu:
- self.conf = FLAGS
- self.config(fake_rabbit=True)
- self.config(rpc_response_timeout=5)
- self.rpc = impl_kombu
+ test.config(fake_rabbit=True)
+ test.config(rpc_response_timeout=5)
+ test.rpc = impl_kombu
self.addCleanup(impl_kombu.cleanup)
else:
- self.rpc = None
+ test.rpc = None
class FakeMessage(object):
@@ -96,11 +105,13 @@ class FakeMessage(object):
class RpcKombuTestCase(amqp.BaseRpcAMQPTestCase):
def setUp(self):
- KombuStubs.setUp(self)
- super(RpcKombuTestCase, self).setUp()
if kombu is None:
self.skipTest("Test requires kombu")
+ self.useFixture(KombuStubs(self))
+
+ super(RpcKombuTestCase, self).setUp()
+
def test_reusing_connection(self):
"""Test that reusing a connection returns same one."""
conn_context = self.rpc.create_connection(FLAGS, new=False)
@@ -704,7 +715,8 @@ class RpcKombuTestCase(amqp.BaseRpcAMQPTestCase):
class RpcKombuHATestCase(utils.BaseTestCase):
def setUp(self):
super(RpcKombuHATestCase, self).setUp()
- KombuStubs.setUp(self)
+
+ self.useFixture(KombuStubs(self))
self.addCleanup(FLAGS.reset)
def test_roundrobin_reconnect(self):