diff --git a/tooz/drivers/etcd.py b/tooz/drivers/etcd.py index 81fb179d..4ff93f3c 100644 --- a/tooz/drivers/etcd.py +++ b/tooz/drivers/etcd.py @@ -133,7 +133,7 @@ class EtcdLock(locking.Lock): try: reply = self.client.get( self._lock_url + - "?wait=true&waitIndex=%d" % reply['index'], + "?wait=true&waitIndex=%d" % (reply['index'] + 1), make_url=False, timeout=watch.leftover() if watch else None) except requests.exceptions.RequestException: diff --git a/tooz/tests/test_etcd.py b/tooz/tests/test_etcd.py new file mode 100644 index 00000000..bbc99e54 --- /dev/null +++ b/tooz/tests/test_etcd.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2016 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import mock +from testtools import testcase + +import tooz.coordination + + +class TestEtcd(testcase.TestCase): + FAKE_URL = "etcd://mocked-not-really-localhost:2379" + FAKE_MEMBER_ID = "mocked-not-really-member" + + def setUp(self): + super(TestEtcd, self).setUp() + self._coord = tooz.coordination.get_coordinator(self.FAKE_URL, + self.FAKE_MEMBER_ID) + + def test_multiple_locks_etcd_wait_index(self): + lock = self._coord.get_lock('mocked-not-really-random') + + return_values = [ + {'errorCode': {}, 'node': {}, 'index': 10}, + {'errorCode': None, 'node': {}, 'index': 10} + ] + with mock.patch.object(lock.client, 'put', side_effect=return_values): + with mock.patch.object(lock.client, 'get') as mocked_get: + self.assertTrue(lock.acquire()) + mocked_get.assert_called_once() + call = str(mocked_get.call_args) + self.assertIn("waitIndex=11", call) diff --git a/tox.ini b/tox.ini index 6e781355..6490e17d 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ envlist = py27,py34,py27-zookeeper,py34-zookeeper,py27-redis,py34-redis,py27-sen [testenv] # We need to install a bit more than just `test' because those drivers have # custom tests that we always run -deps = .[test,zake,ipc,memcached,mysql] +deps = .[test,zake,ipc,memcached,mysql,etcd] py{27,34}-zookeeper: .[zookeeper] py{27,34}-redis: .[redis] py{27,34}-sentinel: .[redis]