]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Ensure test_metaplugin handles random hashseeds
authorSam Betts <sam@code-smash.net>
Mon, 20 Oct 2014 12:26:33 +0000 (13:26 +0100)
committerSam Betts <sam@code-smash.net>
Mon, 5 Jan 2015 10:02:15 +0000 (10:02 +0000)
2 tests fail in test_metaplugin when using hashseed 2701526934 this is
down to the nature of using dictionaries and sets in Python having
unpredictable ordering when retrieving data stored in them. This patch
ensures that no matter the order fake1 and fake2 get placed into
self.plugins that the test can assert both possible scenarios.

Change-Id: I65fa6979cc0d6e3531e50f249c53db6be83a6cfe
Partial-Bug: 1348818

neutron/tests/unit/metaplugin/test_metaplugin.py

index 02104bc20782714f4bdfdbe46324c0e3c67649a2..4f94ed7ac4c6d4c44599ffd3fad286f31580b29f 100644 (file)
@@ -306,7 +306,20 @@ class MetaNeutronPluginV2Test(testlib_api.SqlTestCase,
             self.plugin.get_router(self.context, router_ret1['id'])
 
     def test_extension_method(self):
-        self.assertEqual('fake1', self.plugin.fake_func())
+        """Test if plugin methods are accessible from self.plugin
+
+        This test compensates for the nondeterministic ordering of
+        self.plugin's plugins dictionary. Fake Plugin 1 and Fake Plugin 2
+        both have a function called fake_func and the order of
+        self.plugin.plugins will determine which fake_func is called.
+        """
+        fake1 = self.plugin.plugins.keys().index('fake1')
+        fake2 = self.plugin.plugins.keys().index('fake2')
+        fake1_before_fake2 = fake1 < fake2
+
+        fake_func_return = 'fake1' if fake1_before_fake2 else 'fake2'
+
+        self.assertEqual(fake_func_return, self.plugin.fake_func())
         self.assertEqual('fake2', self.plugin.fake_func2())
 
     def test_extension_not_implemented_method(self):