Fix race in test_keepalived_state_change_notification

In case if initial keepalived status find in
keepalived_state_change.MonitorDaemon is "master"
this test_keepalived_state_change_notification was failing
because there was 4 calls to the mocked enqueue_state_change()
method instead of 3.

This patch changes test to wait until 3 or 4 calls to this
method will be counted and it also changes assertions of
what state should be set on which call.
Before the patch test was expecting that calls are always like:
backup, master, backup
but if there are 4 calls it is like: backup, master, master, backup.
As it doesn't matter if there was one or two calls with "master"
state, test will now assert that the last call is always with
"backup" state.

Change-Id: I78c30ab32ffda37176a9c71348d83e17ab2c972a
Closes-Bug: #1836565
This commit is contained in:
Slawek Kaplonski 2019-07-15 13:03:30 +02:00
parent ccd627c3b3
commit 7bb1bbba36
1 changed files with 3 additions and 2 deletions

View File

@ -45,11 +45,12 @@ class L3HATestCase(framework.L3AgentTestFramework):
self.fail_ha_router(router)
common_utils.wait_until_true(lambda: router.ha_state == 'backup')
common_utils.wait_until_true(lambda: enqueue_mock.call_count == 3)
common_utils.wait_until_true(lambda:
(enqueue_mock.call_count == 3 or enqueue_mock.call_count == 4))
calls = [args[0] for args in enqueue_mock.call_args_list]
self.assertEqual((router.router_id, 'backup'), calls[0])
self.assertEqual((router.router_id, 'master'), calls[1])
self.assertEqual((router.router_id, 'backup'), calls[2])
self.assertEqual((router.router_id, 'backup'), calls[-1])
def _expected_rpc_report(self, expected):
calls = (args[0][1] for args in