Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,3 @@ include =
omit =
kazoo/tests/*
kazoo/testing/*

# Note - this is a copy of the default exclusions from coverage 7.10.1
[report]
exclude_lines =
#\s*(pragma|PRAGMA)[:\s]?\s*(no|NO)\s*(cover|COVER)
^\s*(((async )?def .*?)?\)(\s*->.*?)?:\s*)?\.\.\.\s*(#|$)
if (typing\.)?TYPE_CHECKING:
8 changes: 6 additions & 2 deletions kazoo/protocol/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,12 @@ def _read_watch_event(self, buffer: bytes, offset: int) -> None:
watchers.extend(client._child_watchers.pop(path, []))
elif watch.type == CHILD_EVENT:
watchers.extend(client._child_watchers.pop(path, []))
else:
self.logger.warn("Received unknown event %r", watch.type)
else: # pragma: no cover
# No coverage here because because it'd require an unknown event
# type to be sent from the server. We could do a unit test that
# calls this method directly with a fake event, but that would be
# fragile and not really test the code in a meaningful way.
self.logger.warning("Received unknown event %r", watch.type)
return

# Strip the chroot if needed
Expand Down
20 changes: 6 additions & 14 deletions kazoo/recipe/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import datetime
import json
import socket
from typing import Callable, TypedDict, TYPE_CHECKING, cast
from typing import TypedDict, TYPE_CHECKING, cast

from kazoo.exceptions import CancelledError

Expand Down Expand Up @@ -55,8 +55,8 @@ class NonBlockingLease:
"""

# Bump when storage format changes
_version = 1
_date_format = "%Y-%m-%dT%H:%M:%S"
_version = 2
_date_format = "%Y-%m-%dT%H:%M:%S%z"
_byte_encoding = "utf-8"

def __init__(
Expand All @@ -65,7 +65,6 @@ def __init__(
path: str,
duration: datetime.timedelta,
identifier: str | None = None,
utcnow: Callable[[], datetime.datetime] = datetime.datetime.utcnow,
):
"""Create a non-blocking lease.

Expand All @@ -76,28 +75,25 @@ def __init__(
:param identifier: Unique name to use for this lease holder. Reuse in
order to renew the lease. Defaults to
:meth:`socket.gethostname()`.
:param utcnow: Clock function, by default returning
:meth:`datetime.datetime.utcnow()`. Used for testing.

"""

ident = identifier or socket.gethostname()
self.obtained = False
self._attempt_obtaining(client, path, duration, ident, utcnow)
self._attempt_obtaining(client, path, duration, ident)

def _attempt_obtaining(
self,
client: KazooClient,
path: str,
duration: datetime.timedelta,
ident: str,
utcnow: Callable[[], datetime.datetime],
) -> None:
client.ensure_path(path)
holder_path = path + "/lease_holder"
lock = client.Lock(path, ident)
try:
with lock:
now = utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
if client.exists(holder_path):
raw, _ = client.get(holder_path)
data = self._decode(raw)
Expand Down Expand Up @@ -148,8 +144,6 @@ class MultiNonBlockingLease:
:param identifier: Unique name to use for this lease holder. Reuse in order
to renew the lease.
Defaults do :meth:`socket.gethostname()`.
:param utcnow: Clock function, by default returning
:meth:`datetime.datetime.utcnow()`. Used for testing.

"""

Expand All @@ -160,7 +154,6 @@ def __init__(
path: str,
duration: datetime.timedelta,
identifier: str | None = None,
utcnow: Callable[[], datetime.datetime] = datetime.datetime.utcnow,
):
self.obtained = False
for num in range(count):
Expand All @@ -169,7 +162,6 @@ def __init__(
"%s/%d" % (path, num),
duration,
identifier=identifier,
utcnow=utcnow,
)
if ls:
self.obtained = True
Expand Down
4 changes: 2 additions & 2 deletions kazoo/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import socket
import tempfile
import threading
import time
import uuid
import unittest

Expand Down Expand Up @@ -688,7 +687,8 @@ def test_create_makepath_incompatible_acls(self) -> None:
credential = make_digest_acl_credential("username", "password")
alt_client = KazooClient(
self.cluster[0].address + self.client.chroot,
max_retries=5,
connection_retry=KazooRetry(max_tries=5),
command_retry=KazooRetry(max_tries=5),
auth_data=[("digest", credential)],
handler=self._makeOne(),
)
Expand Down
Loading
Loading