Skip to content

Commit b295ea1

Browse files
committed
Fix tests failing in the 2nd half of the hour
1 parent a06ddcb commit b295ea1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

notifier/deletions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def clear_deleted_posts(
4343

4444
logger.info("Checking for deleted posts to clear")
4545

46+
# Look for deleted posts by rounding down to the previous hour - this ensures consistent raking even when this function is called at irregular intervals
47+
# Process is normally run shortly after the hour so this is approximately accurate - note that this is not the case for tests which can be run at any time
4648
now_hour = timing.now.replace(minute=0, second=0, microsecond=0)
4749
now_hour_ts = int(datetime.timestamp(now_hour))
4850

tests/test_deletions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import time
1+
from datetime import datetime
22
from unittest.mock import MagicMock
33
import pytest
44

5+
from notifier import timing
56
from notifier.database.drivers.base import BaseDatabaseDriver
67
from notifier.database.drivers.mysql import MySqlDriver
78
from notifier.database.utils import resolve_driver_from_config
@@ -30,7 +31,9 @@ def deletions_test_database(
3031
password=notifier_auth["mysql_password"],
3132
)
3233
db.scrub_database()
33-
now = int(time.time())
34+
# Use the same hour-rounded 'now' as the production code
35+
now_hour = timing.now.replace(minute=0, second=0, microsecond=0)
36+
now = int(datetime.timestamp(now_hour))
3437
# Add a wiki, thread, and parent post context
3538
db.store_supported_wikis(
3639
[{"id": "test-wiki", "name": "Test Wiki", "secure": 1}]
@@ -76,7 +79,7 @@ def deletions_test_database(
7679
# Should be selected (5-6 hour window)
7780
{
7881
"post_id": "p-2",
79-
"posted_timestamp": now - 5 * 3600 - 1800, # 5.5 hours ago
82+
"posted_timestamp": now - (5 * 3600) - 1800, # 5.5 hours ago
8083
"post_title": "Should Check 2",
8184
"post_snippet": "",
8285
"author_user_id": "user1",

0 commit comments

Comments
 (0)