fix(timezone): add timezone-aware clock across agent, cron, and execute_code
This commit is contained in:
parent
de0af4df66
commit
a1c25046a9
9 changed files with 475 additions and 29 deletions
|
|
@ -72,8 +72,9 @@ class TestParseSchedule:
|
|||
assert "run_at" in result
|
||||
# run_at should be ~30 minutes from now
|
||||
run_at = datetime.fromisoformat(result["run_at"])
|
||||
assert run_at > datetime.now()
|
||||
assert run_at < datetime.now() + timedelta(minutes=31)
|
||||
now = datetime.now().astimezone()
|
||||
assert run_at > now
|
||||
assert run_at < now + timedelta(minutes=31)
|
||||
|
||||
def test_every_becomes_interval(self):
|
||||
result = parse_schedule("every 2h")
|
||||
|
|
@ -126,15 +127,15 @@ class TestComputeNextRun:
|
|||
result = compute_next_run(schedule)
|
||||
next_dt = datetime.fromisoformat(result)
|
||||
# Should be ~60 minutes from now
|
||||
assert next_dt > datetime.now() + timedelta(minutes=59)
|
||||
assert next_dt > datetime.now().astimezone() + timedelta(minutes=59)
|
||||
|
||||
def test_interval_subsequent_run(self):
|
||||
schedule = {"kind": "interval", "minutes": 30}
|
||||
last = datetime.now().isoformat()
|
||||
last = datetime.now().astimezone().isoformat()
|
||||
result = compute_next_run(schedule, last_run_at=last)
|
||||
next_dt = datetime.fromisoformat(result)
|
||||
# Should be ~30 minutes from last run
|
||||
assert next_dt > datetime.now() + timedelta(minutes=29)
|
||||
assert next_dt > datetime.now().astimezone() + timedelta(minutes=29)
|
||||
|
||||
def test_cron_returns_future(self):
|
||||
pytest.importorskip("croniter")
|
||||
|
|
@ -142,7 +143,7 @@ class TestComputeNextRun:
|
|||
result = compute_next_run(schedule)
|
||||
assert result is not None
|
||||
next_dt = datetime.fromisoformat(result)
|
||||
assert next_dt > datetime.now()
|
||||
assert next_dt > datetime.now().astimezone()
|
||||
|
||||
def test_unknown_kind_returns_none(self):
|
||||
assert compute_next_run({"kind": "unknown"}) is None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue