]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Mock out all RPC calls with a fixture
authorKevin Benton <blak111@gmail.com>
Sat, 20 Sep 2014 17:48:22 +0000 (10:48 -0700)
committerKevin Benton <blak111@gmail.com>
Mon, 22 Sep 2014 12:10:18 +0000 (05:10 -0700)
Mock out the rpc proxy calls used by various agents to
prevent unit tests from blocking for 10+ seconds while waiting
for a timeout. This happened with the OVS agent unit tests
recently in Change-ID Idd770a85a9eabff112d9613e75d8bb524020234a.

This change results in a reduction from 330.8 seconds to 2.7 seconds
for the neutron.tests.unit.openvswitch.test_ovs_neutron_agent
test module.

Closes-Bug: #1372076
Change-Id: I5e6794dc33c64c8fe309d8e72a8af3385c7d4442

neutron/tests/base.py
neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py

index adda2a0bd81fa0ecb4ade23e3990f3d2f84d0a24..dae1320de5cb50b5b3fccec487d9def68b7d2fab 100644 (file)
@@ -125,11 +125,25 @@ class BaseTestCase(testtools.TestCase):
             'neutron.common.exceptions.NeutronException.use_fatal_exceptions',
             fake_use_fatal_exceptions))
 
+        self.setup_rpc_mocks()
+
+        if sys.version_info < (2, 7) and getattr(self, 'fmt', '') == 'xml':
+            raise self.skipException('XML Testing Skipped in Py26')
+
+        self.setup_config()
+        self.addOnException(self.check_for_systemexit)
+
+    def setup_rpc_mocks(self):
         # don't actually start RPC listeners when testing
         self.useFixture(fixtures.MonkeyPatch(
             'neutron.common.rpc.Connection.consume_in_threads',
             fake_consume_in_threads))
 
+        # immediately return RPC calls
+        self.useFixture(fixtures.MonkeyPatch(
+            'neutron.common.rpc.RpcProxy._RpcProxy__call_rpc_method',
+            mock.MagicMock()))
+
         self.useFixture(fixtures.MonkeyPatch(
             'oslo.messaging.Notifier', fake_notifier.FakeNotifier))
 
@@ -144,12 +158,6 @@ class BaseTestCase(testtools.TestCase):
         self.addCleanup(n_rpc.cleanup)
         n_rpc.init(CONF)
 
-        if sys.version_info < (2, 7) and getattr(self, 'fmt', '') == 'xml':
-            raise self.skipException('XML Testing Skipped in Py26')
-
-        self.setup_config()
-        self.addOnException(self.check_for_systemexit)
-
     def check_for_systemexit(self, exc_info):
         if isinstance(exc_info[1], SystemExit):
             self.fail("A SystemExit was raised during the test. %s"
index 3289b34965e7a97bea18ec5dec0c7fbc9dfb5969..6a214dd6f29c016f6613f699bb595cba1e7b4832 100644 (file)
@@ -136,6 +136,9 @@ class TestOvsNeutronAgent(base.BaseTestCase):
                        'FixedIntervalLoopingCall',
                        new=MockFixedIntervalLoopingCall)):
             self.agent = ovs_neutron_agent.OVSNeutronAgent(**kwargs)
+            # set back to true because initial report state will succeed due
+            # to mocked out RPC calls
+            self.agent.use_call = True
             self.agent.tun_br = mock.Mock()
         self.agent.sg_agent = mock.Mock()