]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make plugin deallocation check optional
authorMaru Newby <marun@redhat.com>
Fri, 9 May 2014 22:24:45 +0000 (22:24 +0000)
committerMaru Newby <marun@redhat.com>
Fri, 9 May 2014 22:24:45 +0000 (22:24 +0000)
The fix for memory leakage in the related bug added a check for plugin
deallocation that performed a call to gc.collect() after every test.
This had the side-effect of increasing test execution time by ~50%, so
this patch makes the check optional via an environment variable
(OS_CHECK_PLUGIN_DEALLOCATION).

It may make sense to create a periodic job that runs with the check
enabled, but otherwise the check can be used by developers for
debugging purposes.

Change-Id: I9ebe663abbc4e4ff3a62d807d5a3230c2ecccd07
Related-Bug: #1234857

neutron/tests/base.py

index 75a629e5f302b5c5a6d383c708cb8387bf4d9549..eb1611af843bbefcb2d09e9bdf82789255847935 100644 (file)
@@ -69,13 +69,22 @@ class BaseTestCase(testtools.TestCase):
         #TODO(marun) Fix plugins that do not properly initialize notifiers
         agentschedulers_db.AgentSchedulerDbMixin.agent_notifiers = {}
 
-        plugin = weakref.ref(nm._instance.plugin)
+        # Perform a check for deallocation only if explicitly
+        # configured to do so since calling gc.collect() after every
+        # test increases test suite execution time by ~50%.
+        check_plugin_deallocation = (
+            os.environ.get('OS_CHECK_PLUGIN_DEALLOCATION') in TRUE_STRING)
+        if check_plugin_deallocation:
+            plugin = weakref.ref(nm._instance.plugin)
+
         nm.clear_instance()
-        gc.collect()
 
-        #TODO(marun) Ensure that mocks are deallocated?
-        if plugin() and not isinstance(plugin(), mock.Base):
-            self.fail('The plugin for this test was not deallocated.')
+        if check_plugin_deallocation:
+            gc.collect()
+
+            #TODO(marun) Ensure that mocks are deallocated?
+            if plugin() and not isinstance(plugin(), mock.Base):
+                self.fail('The plugin for this test was not deallocated.')
 
     def setup_coreplugin(self, core_plugin=None):
         if core_plugin is not None: