]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Ensure test_agent_manager handles random hashseeds
authorSam Betts <sam@code-smash.net>
Mon, 20 Oct 2014 09:59:13 +0000 (10:59 +0100)
committerSam Betts <sam@code-smash.net>
Mon, 20 Oct 2014 11:59:01 +0000 (12:59 +0100)
Several tests in test_agent_manager.py fail when tox is run using the
hashseed 2701526934, this is down to the nature of using dictionaries
and sets in Python causing some function calls and function arguments
to be out of order. This patch fixes this by either specifying that
assert_has_calls does not need to assert the order, just that the calls
were made, or by letting the unit test get affected in the same way as
the code, e.g. add variables to a dict so they are ordered by the python
hashing algorithms in the same way as they would be in the real code.

Change-Id: If83d1f33c187eab45c2a65fd50fd70cce011c9e7
Partial-Bug: 1348818

neutron/tests/unit/services/loadbalancer/agent/test_agent_manager.py

index 4e28429026f61aa08a5f4e126f2a72d99c091161..8f63b622232c1522b0cba1955e5a39c37e5a4295 100644 (file)
@@ -67,7 +67,7 @@ class TestManager(base.BaseTestCase):
         self.rpc_mock.update_pool_stats.assert_has_calls([
             mock.call('1', mock.ANY),
             mock.call('2', mock.ANY)
-        ])
+        ], any_order=True)
 
     def test_collect_stats_exception(self):
         self.driver_mock.get_stats.side_effect = Exception
@@ -91,8 +91,10 @@ class TestManager(base.BaseTestCase):
             self.assertEqual(len(reloaded), len(reload.mock_calls))
             self.assertEqual(len(destroyed), len(destroy.mock_calls))
 
-            reload.assert_has_calls([mock.call(i) for i in reloaded])
-            destroy.assert_has_calls([mock.call(i) for i in destroyed])
+            reload.assert_has_calls([mock.call(i) for i in reloaded],
+                                    any_order=True)
+            destroy.assert_has_calls([mock.call(i) for i in destroyed],
+                                     any_order=True)
             self.assertFalse(self.mgr.needs_resync)
 
     def test_sync_state_all_known(self):
@@ -187,7 +189,8 @@ class TestManager(base.BaseTestCase):
 
     def test_remove_orphans(self):
         self.mgr.remove_orphans()
-        self.driver_mock.remove_orphans.assert_called_once_with(['1', '2'])
+        orphans = {'1': "Fake", '2': "Fake"}
+        self.driver_mock.remove_orphans.assert_called_once_with(orphans.keys())
 
     def test_create_vip(self):
         vip = {'id': 'id1', 'pool_id': '1'}
@@ -364,4 +367,4 @@ class TestManager(base.BaseTestCase):
         payload = {'admin_state_up': False}
         self.mgr.agent_updated(mock.Mock(), payload)
         self.driver_mock.undeploy_instance.assert_has_calls(
-            [mock.call('1'), mock.call('2')])
+            [mock.call('1'), mock.call('2')], any_order=True)