From 706deaeaed3c9b8ccd71500590c8d3b3cff5802e Mon Sep 17 00:00:00 2001 From: Sam Betts Date: Mon, 20 Oct 2014 13:26:33 +0100 Subject: [PATCH] Ensure test_metaplugin handles random hashseeds 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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/neutron/tests/unit/metaplugin/test_metaplugin.py b/neutron/tests/unit/metaplugin/test_metaplugin.py index 02104bc20..4f94ed7ac 100644 --- a/neutron/tests/unit/metaplugin/test_metaplugin.py +++ b/neutron/tests/unit/metaplugin/test_metaplugin.py @@ -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): -- 2.45.2