From f9cd68f8d0561606981ead702359b88d80c3206f Mon Sep 17 00:00:00 2001 From: Adam Gandelman Date: Tue, 30 Jun 2015 16:04:01 -0700 Subject: [PATCH] Ensure run_watchers called from mixin, not base class A new mixin was introduced to share run_watchers across drivers, but the base class's run_watchers() currently gets called instead, resulting in a NotImplemented error. Change-Id: I5f23f63100a9c00837025b291cb1db0a5187a8e9 Closes-bug: #1470264 --- tooz/drivers/file.py | 4 ++-- tooz/drivers/memcached.py | 4 ++-- tooz/drivers/redis.py | 4 ++-- tooz/tests/test_memcache.py | 13 +++++++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tooz/drivers/file.py b/tooz/drivers/file.py index 2b0c9b3c..97451dcf 100644 --- a/tooz/drivers/file.py +++ b/tooz/drivers/file.py @@ -110,8 +110,8 @@ class FileLock(locking.Lock): LOG.warn("Unreleased lock %s garbage collected", self.name) -class FileDriver(coordination.CoordinationDriver, - coordination._RunWatchersMixin): +class FileDriver(coordination._RunWatchersMixin, + coordination.CoordinationDriver): """A file based driver. This driver uses files and directories (and associated file locks) to diff --git a/tooz/drivers/memcached.py b/tooz/drivers/memcached.py index 8159dab4..48068752 100644 --- a/tooz/drivers/memcached.py +++ b/tooz/drivers/memcached.py @@ -114,8 +114,8 @@ class MemcachedLock(locking.Lock): return self.coord.client.get(self.name) -class MemcachedDriver(coordination.CoordinationDriver, - coordination._RunWatchersMixin): +class MemcachedDriver(coordination._RunWatchersMixin, + coordination.CoordinationDriver): """A `memcached`_ based driver. This driver users `memcached`_ concepts to provide the coordination driver diff --git a/tooz/drivers/redis.py b/tooz/drivers/redis.py index f02c6b77..0521b492 100644 --- a/tooz/drivers/redis.py +++ b/tooz/drivers/redis.py @@ -98,8 +98,8 @@ class RedisLock(locking.Lock): self._lock.extend(self._lock.timeout) -class RedisDriver(coordination.CoordinationDriver, - coordination._RunWatchersMixin): +class RedisDriver(coordination._RunWatchersMixin, + coordination.CoordinationDriver): """Redis provides a few nice benefits that act as a poormans zookeeper. It **is** fully functional and implements all of the coordination diff --git a/tooz/tests/test_memcache.py b/tooz/tests/test_memcache.py index cae9a5a5..2b1b08cf 100644 --- a/tooz/tests/test_memcache.py +++ b/tooz/tests/test_memcache.py @@ -69,3 +69,16 @@ class TestMemcacheDriverFailures(testcase.TestCase): coord.start() mock_client.set.side_effect = socket.timeout('timed-out') self.assertRaises(coordination.ToozConnectionError, coord.heartbeat) + + @mock.patch('tooz.coordination._RunWatchersMixin.run_watchers', + autospec=True) + @mock.patch('pymemcache.client.PooledClient') + def test_client_run_watchers_mixin(self, mock_client_cls, + mock_run_watchers): + mock_client = mock.MagicMock() + mock_client_cls.return_value = mock_client + member_id = str(uuid.uuid4()).encode('ascii') + coord = coordination.get_coordinator(self.FAKE_URL, member_id) + coord.start() + coord.run_watchers() + self.assertTrue(mock_run_watchers.called)