Skip to content

Commit 53207f5

Browse files
tercelclaude
andcommitted
fix: update scheduler tests for v2 ConfigManager, fix SQLite tz comparisons
Scheduler tests: replace set_api_server_url/load_cli_config with monkeypatch.setenv + cm.reload() (v2 env-var-driven config) Scheduling tests: fix timezone-aware vs naive datetime comparisons (SQLite strips tzinfo, DuckDB preserved it) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 3155a82 commit 53207f5

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

tests/core/storage/sqlalchemy/test_scheduling.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,9 @@ async def test_task_model_with_scheduling(self, sync_db_session):
590590
assert task.schedule_type == ScheduleType.daily.value
591591
assert task.schedule_expression == "09:00"
592592
assert task.schedule_enabled is True
593-
assert task.schedule_start_at == schedule_start
594-
assert task.schedule_end_at == schedule_end
595-
assert task.next_run_at == next_run
593+
assert task.schedule_start_at.replace(tzinfo=None) == schedule_start.replace(tzinfo=None)
594+
assert task.schedule_end_at.replace(tzinfo=None) == schedule_end.replace(tzinfo=None)
595+
assert task.next_run_at.replace(tzinfo=None) == next_run.replace(tzinfo=None)
596596
assert task.max_runs == 100
597597
assert task.run_count == 0
598598

@@ -621,8 +621,8 @@ async def test_task_model_update_scheduling(self, sync_db_session):
621621
assert updated_task.schedule_type == ScheduleType.daily.value
622622
assert updated_task.schedule_expression == "09:00"
623623
assert updated_task.schedule_enabled is True
624-
assert updated_task.last_run_at == last_run
625-
assert updated_task.next_run_at == next_run
624+
assert updated_task.last_run_at.replace(tzinfo=None) == last_run.replace(tzinfo=None)
625+
assert updated_task.next_run_at.replace(tzinfo=None) == next_run.replace(tzinfo=None)
626626
assert updated_task.run_count == 1
627627

628628
def test_task_model_to_dict_scheduling(self):
@@ -732,7 +732,7 @@ async def test_update_task_scheduling_via_repository(self, sync_db_session):
732732
assert updated.schedule_type == "cron"
733733
assert updated.schedule_expression == "0 9 * * 1-5"
734734
assert updated.schedule_enabled is True
735-
assert updated.next_run_at == next_run
735+
assert updated.next_run_at.replace(tzinfo=None) == next_run.replace(tzinfo=None)
736736
assert updated.max_runs == 100
737737

738738
@pytest.mark.asyncio
@@ -1148,7 +1148,7 @@ async def test_complete_scheduled_run(self, sync_db_session):
11481148
assert updated.run_count == 1
11491149
assert updated.last_run_at is not None
11501150
assert updated.next_run_at is not None
1151-
assert updated.next_run_at > now # Next run should be in the future
1151+
assert updated.next_run_at.replace(tzinfo=None) > now.replace(tzinfo=None) # Next run should be in the future
11521152
assert updated.status == "completed" # Preserved from executor
11531153
assert updated.result == {"processed": 100} # Preserved from executor
11541154

tests/scheduler/test_scheduler.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import pytest
1414
from datetime import datetime, timezone, timedelta
15-
from unittest.mock import AsyncMock, MagicMock, patch
15+
from unittest.mock import AsyncMock, MagicMock
1616

1717
from apflow.scheduler.base import (
1818
SchedulerConfig,
@@ -983,34 +983,31 @@ class TestSchedulerAPIDetection:
983983
def _reset_config(self):
984984
"""Reset ConfigManager between tests.
985985
986-
Patches load_cli_config to prevent re-loading from the developer's
987-
local config file (.data/config.cli.yaml), which would re-establish
988-
a real api_server_url and defeat the purpose of cm.clear().
986+
Clears config and env to ensure clean state.
989987
"""
990988
from apflow.core.config_manager import get_config_manager
991989

992990
cm = get_config_manager()
993991
cm.clear()
994-
with patch.object(cm, "load_cli_config"):
995-
yield
992+
yield
996993
cm.clear()
997994

998-
def test_detect_api_mode_true_when_url_configured(self):
999-
"""Detection returns True when api_server_url is configured."""
995+
def test_detect_api_mode_true_when_url_configured(self, monkeypatch):
996+
"""Detection returns True when APFLOW_API_SERVER_URL is set."""
997+
monkeypatch.setenv("APFLOW_API_SERVER_URL", "http://localhost:8000")
1000998
from apflow.core.config_manager import get_config_manager
1001999

1002-
cm = get_config_manager()
1003-
cm.set_api_server_url("http://localhost:8000")
1000+
get_config_manager().reload()
10041001

10051002
scheduler = InternalScheduler()
10061003
assert scheduler._detect_api_mode() is True
10071004

10081005
def test_detect_api_mode_false_when_no_url_configured(self):
1009-
"""Detection returns False when no api_server_url is configured."""
1006+
"""Detection returns False when no APFLOW_API_SERVER_URL is set."""
10101007
scheduler = InternalScheduler()
10111008
assert scheduler._detect_api_mode() is False
10121009

1013-
def test_detect_api_mode_reflects_config_changes(self):
1010+
def test_detect_api_mode_reflects_config_changes(self, monkeypatch):
10141011
"""Detection re-reads ConfigManager on every call (no stale cache)."""
10151012
from apflow.core.config_manager import get_config_manager
10161013

@@ -1019,19 +1016,21 @@ def test_detect_api_mode_reflects_config_changes(self):
10191016

10201017
assert scheduler._detect_api_mode() is False
10211018

1022-
cm.set_api_server_url("http://localhost:8000")
1019+
monkeypatch.setenv("APFLOW_API_SERVER_URL", "http://localhost:8000")
1020+
cm.reload()
10231021
assert scheduler._detect_api_mode() is True
10241022

1025-
cm.set_api_server_url(None)
1023+
monkeypatch.delenv("APFLOW_API_SERVER_URL")
1024+
cm.reload()
10261025
assert scheduler._detect_api_mode() is False
10271026

10281027
@pytest.mark.asyncio
1029-
async def test_start_enables_api_mode_when_url_configured(self):
1028+
async def test_start_enables_api_mode_when_url_configured(self, monkeypatch):
10301029
"""start() detects API and sets _use_api=True when URL configured."""
10311030
from apflow.core.config_manager import get_config_manager
10321031

1033-
cm = get_config_manager()
1034-
cm.set_api_server_url("http://localhost:8000")
1032+
monkeypatch.setenv("APFLOW_API_SERVER_URL", "http://localhost:8000")
1033+
get_config_manager().reload()
10351034

10361035
scheduler = InternalScheduler()
10371036
scheduler._get_due_tasks = AsyncMock(return_value=[])

0 commit comments

Comments
 (0)