NXT 시간외 거래 시간대도 5분 cron 폴링 활성화. 23:30-04:30 dead zone (KIS 점검) → 04:30 까지 skip. 기존 _seconds_until_next_market_open (휴장일/주말용) 와 별개로 _seconds_until_nxt_or_market_open 신설. 3 new tests, scheduler suite 11 passed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
82 lines
2.6 KiB
Python
82 lines
2.6 KiB
Python
"""Tests for scheduler interval logic."""
|
|
from datetime import datetime
|
|
|
|
import pytest
|
|
|
|
from signal_v2.scheduler import _next_interval, _is_market_day, KST
|
|
|
|
|
|
def _kst(year, month, day, hour, minute=0):
|
|
return datetime(year, month, day, hour, minute, tzinfo=KST)
|
|
|
|
|
|
def test_next_interval_pre_market_5min():
|
|
now = _kst(2026, 5, 18, 8, 30) # Monday 08:30
|
|
assert _next_interval(now) == 300
|
|
|
|
|
|
def test_next_interval_market_open_1min():
|
|
now = _kst(2026, 5, 18, 10, 0) # Monday 10:00
|
|
assert _next_interval(now) == 60
|
|
|
|
|
|
def test_next_interval_post_market_5min():
|
|
now = _kst(2026, 5, 18, 17, 0) # Monday 17:00
|
|
assert _next_interval(now) == 300
|
|
|
|
|
|
def test_next_interval_overnight_skip_to_next_morning():
|
|
now = _kst(2026, 5, 18, 2, 30) # Monday 02:30 (dead zone, not NXT window)
|
|
interval = _next_interval(now)
|
|
# Dead zone 23:30-04:30 → next 04:30 is ~2h away
|
|
assert 2 * 3600 - 60 < interval < 2 * 3600 + 60
|
|
|
|
|
|
def test_next_interval_holiday_skip():
|
|
# 2026-05-05 어린이날 (Tuesday holiday)
|
|
now = _kst(2026, 5, 5, 10, 0)
|
|
assert _is_market_day(now) is False
|
|
interval = _next_interval(now)
|
|
# Next: 2026-05-06 (Wed) 07:00, ~21h away
|
|
assert 20 * 3600 < interval < 22 * 3600
|
|
|
|
|
|
def test_next_interval_at_market_open_boundary():
|
|
"""09:00:00 정확 second → 60초 (market 구간 진입)."""
|
|
now = _kst(2026, 5, 18, 9, 0) # Monday 09:00:00
|
|
assert _next_interval(now) == 60
|
|
|
|
|
|
def test_next_interval_at_market_close_boundary():
|
|
"""15:30:00 정확 second → 300초 (post-market 구간 진입)."""
|
|
now = _kst(2026, 5, 18, 15, 30) # Monday 15:30:00
|
|
assert _next_interval(now) == 300
|
|
|
|
|
|
def test_next_interval_at_polling_window_end_boundary():
|
|
"""23:30:00 정확 second → dead zone skip (다음 04:30 까지)."""
|
|
now = _kst(2026, 5, 18, 23, 30) # Monday 23:30:00 (NXT_PRE_END boundary)
|
|
interval = _next_interval(now)
|
|
# Dead zone 23:30-04:30 → next 04:30 is ~5h away
|
|
assert 5 * 3600 - 60 < interval < 5 * 3600 + 60
|
|
|
|
|
|
def test_next_interval_nxt_evening_5min():
|
|
"""22:00 평일 (NXT 야간) → 300 (5분)."""
|
|
now = _kst(2026, 5, 18, 22, 0)
|
|
assert _next_interval(now) == 300
|
|
|
|
|
|
def test_next_interval_nxt_dawn_5min():
|
|
"""05:30 평일 (NXT 새벽) → 300 (5분)."""
|
|
now = _kst(2026, 5, 18, 5, 30)
|
|
assert _next_interval(now) == 300
|
|
|
|
|
|
def test_next_interval_dead_zone_skip():
|
|
"""02:00 평일 (dead zone 23:30-04:30) → 다음 04:30 까지 (~9000s)."""
|
|
now = _kst(2026, 5, 18, 2, 0)
|
|
interval = _next_interval(now)
|
|
# 02:00 → 04:30 = 2.5h = 9000s
|
|
assert 9000 - 60 < interval < 9000 + 60
|