Clean leave group hooks when unwatching.

This commit clean the dict CoordinationDriver._hooks_leave_group
when the user unwatch a given group.

Change-Id: I17adcb0eab556bd97cc0420aec780da8f820f6da
This commit is contained in:
Yassine Lamgarchal
2016-07-17 02:22:55 +02:00
parent 324482fa96
commit c09b20b9a8
2 changed files with 16 additions and 0 deletions

View File

@@ -322,6 +322,9 @@ class CoordinationDriver(object):
group_id in self._group_members):
del self._group_members[group_id]
if not self._hooks_leave_group[group_id]:
del self._hooks_leave_group[group_id]
@abc.abstractmethod
def watch_elected_as_leader(self, group_id, callback):
"""Call a function when member gets elected as leader.

View File

@@ -694,6 +694,19 @@ class TestAPI(tests.TestCaseSkipNotImplemented):
self._coord.unwatch_join_group,
self.group_id, lambda x: None)
def test_unwatch_leave_group(self):
# Create a group and add a leave_group callback
self._coord.create_group(self.group_id).get()
self.assertEqual(0, len(self._coord._hooks_leave_group))
self._coord.watch_leave_group(self.group_id, self._set_event)
# Ensure exactly one leave group hook exists
self.assertEqual(1, len(self._coord._hooks_leave_group[self.group_id]))
# Unwatch, and ensure no leave group hooks exist
self._coord.unwatch_leave_group(self.group_id, self._set_event)
self.assertEqual(0, len(self._coord._hooks_leave_group))
def test_unwatch_leave_group_callback_not_found(self):
self._coord.create_group(self.group_id).get()
self.assertRaises(tooz.coordination.WatchCallbackNotFound,