Skip to content

Make the core reader, watch and session tests wait on state - #520

Merged
yansfil merged 2 commits into
mainfrom
test/core-waits-on-state
Oct 5, 2026
Merged

yansfil merged 2 commits into
mainfrom
test/core-waits-on-state

Conversation

@yansfil

@yansfil yansfil commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Refs #437

Summary

herdr-core의 #437 allow 15개(reader, ai, changes, runtime/session_search, worktree_behavior_tests, live, remote/host)를 없앱니다. 제품 코드는 바뀌지 않았습니다.

  • 상태를 기다리게 바꾼 것
    • reader.rs: settle이 sleep 루프 대신 poll, 그다음 join_pending()(worker가 답을 보냄), 그다음 poll로 답을 받습니다. 20ms를 자던 두 읽기는 test가 채널로 붙잡았다 놓는 held_read가 되어, "첫 poll은 막히지 않는다"와 "요청이 바뀐 동안 읽기가 아직 돈다"가 매번 성립합니다.
    • ai.rs, changes.rs: 500×2ms 루프 대신 read_if_due, 그다음 inner.join_pending(), 그다음 read_if_due.
    • runtime/session_search.rs: 1ms 루프 대신 Drop이 stop을 세우고 깨우는 mailbox의 condition variable(wait_timeout_while)을 기다립니다.
    • worktree_behavior_tests.rs a_watch_change_during_a_read_keeps_the_old_answer_stale: 붙잡힌 읽기를 놓은 뒤 worker를 join하고 답을 한 번 읽습니다.
    • remote/host.rs probe(#[ignore]): 닫힘을 Mutex 대신 채널로 받습니다.
  • 울타리(sentinel)로 바꾼 부재 확인: idle_and_working_tree_edits_do_not_reread_but_manual_refresh_does는 20초 동안 다시 읽지 않는지를 보던 것을, 아무 읽기도 보지 않는 ref(refs/sentinel/<name>)를 쓰고 reader의 Git watch 큐에 그게 오기 전 다른 Git 사실이 없음을 보는 것으로 바꿨습니다. watch 큐는 시스템이 알린 순서대로 경로를 쌓으므로, reader 자신의 읽기가 Git 사실을 바꿨다면 그 변경은 이미 pending에 있거나 sentinel보다 앞에 있습니다. 작업 트리 편집도 같은 방식으로 봅니다. 이 test는 20초에서 1초 밑으로 줄었습니다.
  • 기대값을 밖에서 가져온 것: linked_worktrees_carry_their_creation_time_and_the_main_worktree_none의 20ms를 없애고, 각 줄의 시간이 그 worktree의 .git/worktrees/<name> birth time과 같은지 봅니다(older <= newer는 그대로).
  • 이름 붙은 polling helper로 옮긴 것(벽시계 debounce나 다른 프로세스 상태라 기다릴 단일 상태가 없음): next_answer(Git watch 300ms debounce), answer_after_spacing(reader spacing), queued(Gate는 대기열에 들 때 깨우지 않음), remote_snapshot_until(#[ignore] 원격 probe).

Review

  • 판단해 주세요 (재분류 2개)

    자리 새 allow 이유 왜 상태를 기다릴 수 없나 창
    live.rs reap_local_terminal_child a production wait, not test code test가 아니라 제품의 터미널 reaper입니다(child가 스스로 끝날 200ms 유예 뒤 kill_tree). Rust tests sleep instead of waiting for a state or injecting the clock #437 표에 test로 잘못 들어 있었습니다. OwnedChild에 기한 있는 wait가 없고, hide-platform의 run_to_end도 같은 이유로 같은 allow를 씁니다. 바꾸지 않음
    remote/host.rs a_draining_connection_... a window in which the idle wait must not end: no state reports an event that has not happened wait_idle이 condition variable에서 기다리는 중이라는 것을 밖에서 볼 수 없습니다(감독 답 (2)). 100ms 그대로, thread가 wait_idle 직전에 보내는 신호를 받은 뒤에만
  • 조심해서 볼 파일: herdr-core/src/worktree_behavior_tests.rs changes_before_sentinel - test가 reader의 git_watch 큐를 직접 비웁니다(같은 모듈의 비공개 필드). sentinel이 쓰이며 생기는 폴더와 lock 파일 경로는 sentinel 자신의 것으로 셉니다.

  • 질문: 없음.

Evidence

  • 확인한 것: planted defect - (1) hide-host git_within에서 --no-optional-locks를 빼자 idle test가 "the reader's own read changed a Git fact"로 3/3 실패. (2) 생성 시간을 git_dir 대신 common_dir의 birth time으로 읽게 하자 creation time test가 3/3 실패(두 줄이 같은 값이라 옛 older <= newer로는 통과했을 결함). 되돌리면 통과.
  • 확인한 것: verify-cargo.sh clippy -p herdr-core --all-targets -D warnings, fmt, 바꾼 모듈 test 30개 통과(macOS).
  • 부하 반복 (macOS, yes 4개 + taskpolicy -b, 수정 전과 후 binary를 번갈아 30번씩, 바꾼 test 13개를 한 번에 --test-threads=4): 수정 전 29/30, 수정 후 29/30.
    • 수정 전 실패 1번은 reader::tests::a_request_that_moves_inside_the_spacing_waits_for_it_and_is_then_read(reader.rs:230)로, 이 PR이 reader.settled에서 재도록 고친 경합입니다.
    • 수정 후 실패 1번은 다른 부하(e2e 실행과 yes 4개 추가)가 겹친 시각에 worktree test 2개가 git의 15초 한도에 걸린 것입니다(git commit did not finish within 15 s, 첫 읽기 15초). 수정 전에도 같은 부하에서 git init did not finish within 15 s로 실패한 적이 있는 background QoS 기아로 봅니다.
  • 확인하지 못한 것: 남은 Rust tests sleep instead of waiting for a state or injecting the clock #437 allow는 이 PR만 놓고 main 51에서 36, 열린 Make the platform ipc and watch tests wait for the peer instead of a time #509 #512와 함께 14개(hide-host, hided, hide-kit, hide-ai)입니다.

Reader tests join the worker or hold the read on a channel; the AI and
changes readers join their worker; the session search drop test waits on
the mailbox's condition variable; the worktree idle check writes a sentinel
ref and asserts nothing reached the Git watch before it; the creation time
test compares with the gitdir's birth time; Git-debounced waits and the
remote probes poll through named helpers; the terminal reaper is production
code and says so; the drain test keeps its window, opened only after the
idle wait has started.
The test measured from when its own thread next ran, which can be later
than the settle under load and made a correct spacing look too short.
@yansfil
yansfil added this pull request to the merge queue Oct 5, 2026
Merged via the queue into main with commit 87466ac Oct 5, 2026
53 of 55 checks passed
@yansfil
yansfil deleted the test/core-waits-on-state branch October 5, 2026 16:15
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