Skip to content

Commit a4efaac

Browse files
pmazziniceache
authored andcommitted
[lock] interoperate with go client
1 parent b20c929 commit a4efaac

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

kazoo/recipe/lock.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Lock(object):
8080

8181
# Node names which exclude this contender when present at a lower
8282
# sequence number. Involved in read/write locks.
83-
_EXCLUDE_NAMES = ["__lock__"]
83+
_EXCLUDE_NAMES = ["__lock__", "-lock-"]
8484

8585
def __init__(self, client, path, identifier=None):
8686
"""Create a Kazoo lock.
@@ -289,7 +289,7 @@ def _get_sorted_children(self):
289289
# (eg. in case of a lease), just sort them last ('~' sorts after all
290290
# ASCII digits).
291291
def _seq(c):
292-
for name in ["__lock__", "__rlock__"]:
292+
for name in ["__lock__", "-lock-", "__rlock__"]:
293293
idx = c.find(name)
294294
if idx != -1:
295295
return c[idx + len(name):]
@@ -392,7 +392,7 @@ class WriteLock(Lock):
392392
393393
"""
394394
_NODE_NAME = "__lock__"
395-
_EXCLUDE_NAMES = ["__lock__", "__rlock__"]
395+
_EXCLUDE_NAMES = ["__lock__", "-lock-", "__rlock__"]
396396

397397

398398
class ReadLock(Lock):
@@ -421,7 +421,7 @@ class ReadLock(Lock):
421421
422422
"""
423423
_NODE_NAME = "__rlock__"
424-
_EXCLUDE_NAMES = ["__lock__"]
424+
_EXCLUDE_NAMES = ["__lock__", "-lock-"]
425425

426426

427427
class Semaphore(object):

kazoo/tests/test_lock.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import collections
2+
import mock
23
import threading
4+
import unittest
35
import uuid
46

57
import pytest
68

79
from kazoo.exceptions import CancelledError
810
from kazoo.exceptions import LockTimeout
911
from kazoo.exceptions import NoNodeError
12+
from kazoo.recipe.lock import Lock
1013
from kazoo.testing import KazooTestCase
1114
from kazoo.tests import util as test_util
1215

@@ -716,3 +719,16 @@ def _thread(sem, event, timeout):
716719
# Cleanup
717720
t.join()
718721
client2.stop()
722+
723+
724+
class TestSequence(unittest.TestCase):
725+
726+
def test_get_sorted_children(self):
727+
goLock = "_c_8eb60557ba51e0da67eefc47467d3f34-lock-0000000031"
728+
pyLock = "514e5a831836450cb1a56c741e990fd8__lock__0000000032"
729+
children = [goLock, pyLock]
730+
client = mock.MagicMock()
731+
client.get_children.return_value = children
732+
lock = Lock(client, "test")
733+
sorted_children = lock._get_sorted_children()
734+
assert sorted_children[0] == goLock

0 commit comments

Comments
 (0)