Skip to content

Give the AI router one injectable clock and move its cooldown tests by hand - #527

Merged
yansfil merged 1 commit into
mainfrom
test/router-clock
Oct 5, 2026
Merged

yansfil merged 1 commit into
mainfrom
test/router-clock

Conversation

@yansfil

@yansfil yansfil commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Refs #437

Summary

hide-ai/src/router.rs cooldown test 2개의 #437 allow를 없앱니다. 200ms park가 지나도록 250ms 자던 것을, 시계를 손으로 옮기는 것으로 바꿨습니다.

  • AiRouter에 시계 하나(now)를 두고, park, availability cache 창, 분당 창, 소요 시간이 모두 그 시계를 읽습니다. 기본값은 시스템 monotonic clock(Instant::now)이고, test만 with_clock(#[cfg(test)], 비공개)으로 다른 시계를 줍니다. 공개 API는 바뀌지 않습니다.
  • park test는 이제 reset 양쪽을 봅니다: 199ms에는 아직 park, 200ms에는 풀림. 이전에는 250ms 뒤 풀림만 봐서, park가 reset보다 짧게 끝나는 결함을 잡지 못했습니다.
  • docs/TESTING.md 규칙 4에 "여러 곳에서 시간을 읽는 component는 시계 하나를 받는다"는 예로 AiRouter::with_clock을 적었습니다.

Review

  • 판단해 주세요: 감독 답대로 제품 변경은 주입 지점 하나(now 필드)로 두고 기본값은 실제 시계입니다. elapsed() 호출도 같은 시계의 saturating_duration_since로 바꿨습니다. 실제 시계에서는 같은 값입니다.
  • 조심해서 볼 파일: hide-ai/src/router.rs - Instant::now()를 직접 읽는 곳이 남으면 그 창만 test 시계를 따르지 않습니다. 지금은 router 안에 남은 곳이 없습니다.
  • 질문: 없음.

Evidence

  • 확인한 것 (planted defect): park 길이를 wait / 2로 줄이자 park test가 199ms 단정에서 실패. 되돌리면 통과. 옛 test(250ms 뒤 풀림만 봄)는 이 결함에서도 통과했습니다.
  • 확인한 것: verify-cargo.sh clippy -p hide-ai --all-targets -D warnings, fmt, router test 22개 통과(macOS).
  • 부하 반복: 바뀐 test는 실제 시간을 기다리지 않습니다. yes 4개 + taskpolicy -b 아래 수정 전과 후 binary를 번갈아 30번씩: 30/30 대 30/30(매 회 2개 실행). 수정 전도 흔들리지 않아 고친 위험은 읽기로 판단한 위험입니다(250ms sleep이 200ms park보다 길다는 가정, 그리고 park가 일찍 끝나는 결함을 놓치는 거짓 통과).
  • 확인하지 못한 것: 남은 Rust tests sleep instead of waiting for a state or injecting the clock #437 allow는 이 PR만 놓고 main 51에서 49입니다.

…y hand

Every park, availability cache window and per-minute window in the router
reads one clock, the system's monotonic clock unless a test passes another
through AiRouter::with_clock. The two cooldown tests advance a manual
clock instead of sleeping past a 200 ms park, and the park test now checks
both sides of the reset: still parked 1 ms before it, free at it.
@yansfil
yansfil added this pull request to the merge queue Oct 5, 2026
Merged via the queue into main with commit d98a4e8 Oct 5, 2026
21 checks passed
@yansfil
yansfil deleted the test/router-clock branch October 5, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant