diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2020-04-09 14:28:02 +0100 |
---|---|---|
committer | Charles-Henri de Boysson <ceache@users.noreply.github.com> | 2020-04-24 22:37:57 -0400 |
commit | a4efaac6cf4269a5e322a45c5d650ac2227952d4 (patch) | |
tree | 4157544556abecef553e554e8583a5c24079d1f1 | |
parent | b20c929421ff72421ad3770fb3436d583df5e5b0 (diff) | |
download | kazoo-a4efaac6cf4269a5e322a45c5d650ac2227952d4.tar.gz |
[lock] interoperate with go client
-rw-r--r-- | kazoo/recipe/lock.py | 8 | ||||
-rw-r--r-- | kazoo/tests/test_lock.py | 16 |
2 files changed, 20 insertions, 4 deletions
diff --git a/kazoo/recipe/lock.py b/kazoo/recipe/lock.py index 9bd5dc0..9470299 100644 --- a/kazoo/recipe/lock.py +++ b/kazoo/recipe/lock.py @@ -80,7 +80,7 @@ class Lock(object): # Node names which exclude this contender when present at a lower # sequence number. Involved in read/write locks. - _EXCLUDE_NAMES = ["__lock__"] + _EXCLUDE_NAMES = ["__lock__", "-lock-"] def __init__(self, client, path, identifier=None): """Create a Kazoo lock. @@ -289,7 +289,7 @@ class Lock(object): # (eg. in case of a lease), just sort them last ('~' sorts after all # ASCII digits). def _seq(c): - for name in ["__lock__", "__rlock__"]: + for name in ["__lock__", "-lock-", "__rlock__"]: idx = c.find(name) if idx != -1: return c[idx + len(name):] @@ -392,7 +392,7 @@ class WriteLock(Lock): """ _NODE_NAME = "__lock__" - _EXCLUDE_NAMES = ["__lock__", "__rlock__"] + _EXCLUDE_NAMES = ["__lock__", "-lock-", "__rlock__"] class ReadLock(Lock): @@ -421,7 +421,7 @@ class ReadLock(Lock): """ _NODE_NAME = "__rlock__" - _EXCLUDE_NAMES = ["__lock__"] + _EXCLUDE_NAMES = ["__lock__", "-lock-"] class Semaphore(object): diff --git a/kazoo/tests/test_lock.py b/kazoo/tests/test_lock.py index ee0ff3d..1b6849e 100644 --- a/kazoo/tests/test_lock.py +++ b/kazoo/tests/test_lock.py @@ -1,5 +1,7 @@ import collections +import mock import threading +import unittest import uuid import pytest @@ -7,6 +9,7 @@ import pytest from kazoo.exceptions import CancelledError from kazoo.exceptions import LockTimeout from kazoo.exceptions import NoNodeError +from kazoo.recipe.lock import Lock from kazoo.testing import KazooTestCase from kazoo.tests import util as test_util @@ -716,3 +719,16 @@ class TestSemaphore(KazooTestCase): # Cleanup t.join() client2.stop() + + +class TestSequence(unittest.TestCase): + + def test_get_sorted_children(self): + goLock = "_c_8eb60557ba51e0da67eefc47467d3f34-lock-0000000031" + pyLock = "514e5a831836450cb1a56c741e990fd8__lock__0000000032" + children = [goLock, pyLock] + client = mock.MagicMock() + client.get_children.return_value = children + lock = Lock(client, "test") + sorted_children = lock._get_sorted_children() + assert sorted_children[0] == goLock |