Improved code quality with more idiomatic Python patterns.
This commit is contained in:
@@ -22,7 +22,8 @@ from typing import TYPE_CHECKING
|
||||
import pytest
|
||||
from aioresponses import aioresponses
|
||||
|
||||
from owncastsentry.health_checker import HealthChecker, HealthStatus, UpdateResult
|
||||
from owncastsentry.health_checker import HealthChecker, HealthStatus
|
||||
from owncastsentry.models import UpdateResult
|
||||
from owncastsentry.owncast_client import OwncastClient
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
@@ -62,7 +62,7 @@ class TestCanNotify:
|
||||
service = _make_service(
|
||||
client=_StubMatrixClient(), subscription_repo=subscription_repo
|
||||
)
|
||||
service.notification_timers_cache["example.com"] = time.time()
|
||||
service.notification_timers_cache["example.com"] = time.monotonic()
|
||||
assert service._can_notify("example.com") is False
|
||||
|
||||
def test_after_cooldown_allowed(
|
||||
@@ -74,7 +74,7 @@ class TestCanNotify:
|
||||
)
|
||||
# Subtract an extra second to ensure the cooldown has fully elapsed
|
||||
service.notification_timers_cache["example.com"] = (
|
||||
time.time() - SECONDS_BETWEEN_NOTIFICATIONS - 1
|
||||
time.monotonic() - SECONDS_BETWEEN_NOTIFICATIONS - 1
|
||||
)
|
||||
assert service._can_notify("example.com") is True
|
||||
|
||||
@@ -253,7 +253,7 @@ class TestNotifyStreamLive:
|
||||
"""Skip sending when the domain is within the rate-limit cooldown."""
|
||||
client = _StubMatrixClient()
|
||||
service = _make_service(client=client, subscription_repo=subscription_repo)
|
||||
service.notification_timers_cache["example.com"] = time.time()
|
||||
service.notification_timers_cache["example.com"] = time.monotonic()
|
||||
|
||||
await stream_repo.create("example.com")
|
||||
await subscription_repo.add("example.com", "!room1:matrix.org")
|
||||
|
||||
@@ -337,7 +337,7 @@ class TestUpdateStreamBriefOffline:
|
||||
)
|
||||
|
||||
# Recently offline (within cooldown)
|
||||
monitor.offline_timer_cache["brief.com"] = time.time() - 60
|
||||
monitor.offline_timer_cache["brief.com"] = time.monotonic() - 60
|
||||
|
||||
result = await monitor.update_stream("brief.com")
|
||||
assert result is True
|
||||
@@ -375,7 +375,7 @@ class TestUpdateStreamBriefOffline:
|
||||
)
|
||||
|
||||
# Recently offline (within cooldown)
|
||||
monitor.offline_timer_cache["brief.com"] = time.time() - 60
|
||||
monitor.offline_timer_cache["brief.com"] = time.monotonic() - 60
|
||||
|
||||
result = await monitor.update_stream("brief.com")
|
||||
assert result is True
|
||||
@@ -424,7 +424,7 @@ class TestUpdateStreamTitleChange:
|
||||
monitor.offline_timer_cache["title.com"] = 0
|
||||
# Subtract an extra second to ensure the cooldown has fully elapsed
|
||||
notification_service.notification_timers_cache["title.com"] = (
|
||||
time.time() - SECONDS_BETWEEN_NOTIFICATIONS - 1
|
||||
time.monotonic() - SECONDS_BETWEEN_NOTIFICATIONS - 1
|
||||
)
|
||||
|
||||
result = await monitor.update_stream("title.com")
|
||||
@@ -473,7 +473,7 @@ class TestUpdateStreamTitleChange:
|
||||
monitor.offline_timer_cache["title.com"] = 0
|
||||
# Subtract an extra second to ensure the cooldown has fully elapsed
|
||||
notification_service.notification_timers_cache["title.com"] = (
|
||||
time.time() - SECONDS_BETWEEN_NOTIFICATIONS - 1
|
||||
time.monotonic() - SECONDS_BETWEEN_NOTIFICATIONS - 1
|
||||
)
|
||||
|
||||
result = await monitor.update_stream("title.com")
|
||||
@@ -518,7 +518,7 @@ class TestUpdateStreamTitleChange:
|
||||
|
||||
# Offline timer is MORE recent than last notification,
|
||||
# and both are old enough to pass rate limiting
|
||||
now = time.time()
|
||||
now = time.monotonic()
|
||||
monitor.offline_timer_cache["title.com"] = (
|
||||
now - SECONDS_BETWEEN_NOTIFICATIONS - 100
|
||||
)
|
||||
@@ -571,9 +571,9 @@ class TestUpdateStreamGoesOffline:
|
||||
)
|
||||
monitor.offline_timer_cache["offline.com"] = 0
|
||||
|
||||
before = time.time()
|
||||
before = time.monotonic()
|
||||
result = await monitor.update_stream("offline.com")
|
||||
after = time.time()
|
||||
after = time.monotonic()
|
||||
|
||||
assert result is True
|
||||
assert before <= monitor.offline_timer_cache["offline.com"] <= after
|
||||
|
||||
Reference in New Issue
Block a user