Ensure unwatch_elected_as_leader correctly clears hooks
The default unwatch_elected_as_leader implementation had a typo preventing the method from suceeding. Change-Id: Ib49cbd6558499ff8cd074bf8f2c9a26782a2146c Closes-Bug: 1467907
This commit is contained in:
parent
3361ef1473
commit
03dbde52c1
@ -160,8 +160,8 @@ class CoordinationDriver(object):
|
||||
|
||||
"""
|
||||
self._hooks_elected_leader[group_id].remove(callback)
|
||||
if not self._hooks.elected_leader[group_id]:
|
||||
del self._hooks.elected_leader[group_id]
|
||||
if not self._hooks_elected_leader[group_id]:
|
||||
del self._hooks_elected_leader[group_id]
|
||||
|
||||
@staticmethod
|
||||
def stand_down_group_leader(group_id):
|
||||
|
@ -586,6 +586,18 @@ class TestAPI(testscenarios.TestWithScenarios,
|
||||
self.assertEqual(self.group_id,
|
||||
self.event.group_id)
|
||||
|
||||
def test_unwatch_elected_as_leader(self):
|
||||
# Create a group and add a elected_as_leader callback
|
||||
self._coord.create_group(self.group_id).get()
|
||||
self._coord.watch_elected_as_leader(self.group_id, self._set_event)
|
||||
|
||||
# Ensure exactly one leader election hook exists
|
||||
self.assertEqual(1, len(self._coord._hooks_elected_leader))
|
||||
|
||||
# Unwatch, and ensure no leader election hooks exist
|
||||
self._coord.unwatch_elected_as_leader(self.group_id, self._set_event)
|
||||
self.assertEqual(0, len(self._coord._hooks_elected_leader))
|
||||
|
||||
def test_get_lock(self):
|
||||
lock = self._coord.get_lock(self._get_random_uuid())
|
||||
self.assertTrue(lock.acquire())
|
||||
|
Loading…
Reference in New Issue
Block a user