Repository navigation
test(watcher): de-flake and leak-proof the watcher-lock suite - #904
mattwwatson wants to merge 2 commits into
Conversation
0a0d42c to
de7c31a
Compare
|
Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch. When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again. Noted for firstmate#904 at |
|
Automated reminder: this PR still looks blocked on a rebase or merge conflict fix. If you are still interested, please rebase onto the current base branch, resolve the conflict, and push. If I do not hear back, I may close this as inactive. |
The watcher-lock suite raced its peer processes (peers were assumed started without confirmation) and leaked background children on failure exits, which could hang the suite's output pipe and hold a temp home's watcher lock. De-flake it at the root: exec-confirmed peer starts, durable-file synchronization instead of sleeps, a self-checking bash peer, and an injectable FM_ARM_CONFIRM_TIMEOUT. Leak-proof the harness with file-backed pid and temp registries in tests/lib.sh plus a home-scoped reaper (fm_test_track_pid), and document the convention in CONTRIBUTING.md: nothing is ever reaped by process-name pattern.
de7c31a to
8ebfe56
Compare
|
Checked on a Windows 11 build of main (11bb6738, Still broken. Workbook with sheets
|
1 similar comment
|
Checked on a Windows 11 build of main (11bb6738, Still broken. Workbook with sheets
|
라이브 QA 결과 (iPhone 17 시뮬레이터, dev 서버, head
|
| # | 시나리오 | 판정 | 근거 |
|---|---|---|---|
| a | 날짜 시트: 닫힘→행 탭→열림 / 열림→행 탭→유지 / 행 밖 탭→닫힘 | 통과 | 등록 화면·수정 화면(입영일 설정) 모두 세 동작 확인 |
| b | 스크롤·화면 전환 뒤에도 (a) 동작 | 통과 (수정 화면 기준) | 나갔다 → 수정 화면 스크롤 → 재진입 뒤 같은 동작. 시트를 열어 둔 채 가장자리 스와이프로 뒤로 가는 경로는 판정 불가 |
| c | 상세유형만 바꿔 저장 → 서버 반영, 카드는 서버 기본값 | 통과 | 현역병→상근예비역(육군 유지). UpdateCalculatorService(category) → UpdateCalculatorService(category+branch) 모두 200, 각각 Idempotency-Key 포함. 비기본 카드 구성을 저장해 둔 뒤였는데 UpdateSoldierPreviewPropertyTypeList는 한 번도 나가지 않았고, 이후 GetPreviewItemSettingsScreen 응답이 서버 기본 목록으로 돌아와 있음 |
| d | 「확인이 필요해요」 표시·같은 값 저장 시 꺼짐·Idempotency-Key·실패 시 성공처럼 보이지 않음 | 부분 통과 | 서버에 플래그가 켜진 dev 계산기가 없어 앱 캐시 값을 강제로 켜서 확인함. 표시 ✔, 같은 값 저장 시 confirm mutation(Idempotency-Key 포함) 200 후 표시 사라짐 ✔, 요청을 네트워크 오류로 실패시키면 오류 토스트만 뜨고 성공 토스트·플래그 해제 없음 ✔. 서버가 실제 플래그를 끄는지는 미확인 |
| e | 등록·수정·미리보기·삭제 전체 흐름 | 통과 | RegisterCalculator(Idempotency-Key: calculator-register-…) 200, 미리보기 PreviewCalculatorChange 200, 이름·카드 저장 200, DeleteCalculatorServiceSoldier 200 후 서버 목록에서 사라짐 |
| f | 전역일·진급일·구간이 서버 응답과 일치 | 통과 | 서버 endDate 2028-05-01T15:00Z(=KST 5/2), 진급 2027-02-01 / 2027-08-01 / 2028-02-01 모두 등록 검토·상세·수정 화면과 일치, D-day·복무일(547/546)도 일치 |
| g | 셀럽 군인프로필 복사 중 네트워크 오류 시 대화상자 한 번 | 조건부 통과 + 결함 후보 | 복사 요청을 실패시켰을 때 화면에는 오류 토스트가 1개만 보임(30fps 영상 확인) |
확인한 결함 후보 (고치지 않음)
- g — 오류 안내 이중 호출:
features/cheer/celebrity-header/components/celebrity-header.tsx의 복사 핸들러가onError: handleMutationError와try/catch를 함께 써서, 네트워크 오류 시onError가 "인터넷에 연결되어 있지 않아요" 안내를 호출한 뒤data가 비어catch가 "문제가 발생했습니다…" 안내를 다시 호출해요. 화면에는 나중 것만 보여서 오프라인 안내가 사라져요(수정 화면 저장 실패에서는 오프라인 안내가 정상 표시됨). 재현: 셀럽 상세에서 "군인프로필 복사" → 확인 → 광고 종료 시점에 네트워크 오류. 토스트 호출 횟수를 직접 세지는 못해서 "화면에 1개"는 확인, "호출 1회"는 코드 읽기로만 추정이에요.
관찰 (결함 여부 미확정)
- 등록 직후 홈 캐러셀에 새 계산기가 바로 보이지 않고, 목록 화면을 열어 대시보드 목록이 재조회된 뒤에 나타나요. PR 이전 동작과는 비교하지 못했어요.
- 상세유형 변경 한 번에 쓰기 요청이 2번(category / category+branch) 나가요. 서로 다른
Idempotency-Key를 쓰고 있어 의도된 흐름이면 문제없어요. - 셀럽 복사
CreateSoldierFromCelebrity요청에는Idempotency-Key가 없어요. 계약상 필요한지는 확인하지 못했어요.
확인하지 못한 것
- d의 서버 측 플래그 해제(서버 플래그가 켜진 dev 계산기 필요).
- 시트가 열린 채 화면 전환(b 일부), 등록 화면에서의 스크롤 후 재검증.
- 호봉 승급 등 클라이언트 계산 값은 서버 응답과 대조하지 않았어요.
테스트 광고(App Store 시트, 전면 광고, 인앱 브라우저)가 겹쳤지만 닫고 진행했고 판정이 막힌 항목은 없어요.
|
Speaking as Kun's firstmate: thank you @mattwwatson for this, and I'm sorry it sat so long without a real review. I read head Waiting on you, no rush: is there still a part main doesn't cover? Two examples would be Contract-class: cannot-tell for now, because the branch can't be judged against current main. VISION.md: test hygiene and leak-proof fixtures align ("field incidents become regression coverage"). Nothing here conflicts with the vision. |
|
Closing this - it has drifted a long way behind main and no longer applies cleanly. If the problem still reproduces on current main I'll raise it fresh. Thanks. |
Intent
Upstream contribution from the mattwwatson/firstmate fork: de-flake and leak-proof the watcher-lock test suite at the root. Peer watcher starts are now exec-confirmed with durable-file synchronization instead of sleeps, a self-checking bash peer, and an injectable FM_ARM_CONFIRM_TIMEOUT; tests/lib.sh gains file-backed pid and temp registries with a home-scoped reaper (fm_test_track_pid) so no failure path leaks background processes or holds a temp home's watcher lock, and CONTRIBUTING.md documents the convention (nothing reaped by process-name pattern). The CONTRIBUTING.md paragraph was hand-merged onto the current upstream testing-docs rewrite, keeping upstream's fm-test-run.sh section intact and appending only the two new convention sentences. Suite passes 28/28 locally on the upstream base.
What Changed
FM_ARM_CONFIRM_TIMEOUT, and anfm-watch-arm.shtweak that surfaces the finished child's stand-down output before the successor-confirmation wait so tests can synchronize on it.tests/lib.sh(stored in a privatemktemp -ddirectory) with a home-scoped reaper viafm_test_track_pid, so failing test paths no longer leak background processes or hold a temp home's watcher lock — nothing is reaped by process-name pattern. Suites that install custom EXIT traps now drain these registries in their own cleanup.fm-test-run.shtesting section. Suite verified 28/28 across three consecutive runs in the pipeline, including its built-in no-leaked-process/no-held-lock audit.Risk Assessment
✅ Low: The final commit cleanly closes the round-2 registry-dir leak by adding idempotent, exit-status-preserving fm_test_cleanup calls to the exact three non-conforming suites, and the full branch now satisfies every stated intent criterion with no outstanding source findings.
Testing
Ran the watcher-lock suite three times through the canonical runner (28/28 each, no flakes), ran the three other touched suites (pass/clean self-skip), and demonstrated the leak-proofing end-to-end with a fail()-aborted real-arm demo (children reaped, lock released, 5s pipe EOF) against a pre-change contrast that hung the pipe 76s; before/after audits show zero leaked processes or temp dirs and the user's real watcher untouched. No UI surface — this is CLI/test infrastructure, so transcripts are the reviewer-visible evidence.
Evidence: watcher-lock suite run 1 transcript (28/28 ok)
Evidence: watcher-lock suite run 2 transcript (28/28 ok)
Evidence: watcher-lock suite run 3 transcript (28/28 ok)
Evidence: Fail-path leak demo transcript — tracked arm+watcher reaped after mid-case fail(), lock released, 5s pipe EOF
demo exit=1 (expected nonzero: fail() aborted the case) seconds-to-EOF=5 (a leaked child would hold the pipe open and hang this read) arm pid 65278: gone (reaped) watcher grandchild pid 65293: gone (reaped) temp root .../fm-leak-demo.lDnZPj: removed (watcher lock released with it)Evidence: Pre-change contrast transcript — untracked children held the output pipe 76s past the abort
Evidence: Fail-path demo script (replicates a watcher-lock case with the new registry convention)
Evidence: Other touched suites transcript (tmux 4/4 ok; herdr e2e clean opt-in skips)
Evidence: Leak audit: TMPDIR fm-* dirs and watcher processes before/after all runs (zero suite leftovers)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed (2) ✅
tests/lib.sh:85- The file-backed registries use predictable world-tmp paths (${TMPDIR:-/tmp}/fm-test-cleanup.$$andfm-test-pids.$$), and fm_test_cleanup laterrm -rfs every path read back from the cleanup log (guarded only against empty and/). On a multi-user machine another user can pre-create or symlink those names — sticky-bit /tmp even makes the source-timerm -fof a foreign-owned planted file fail silently — letting planted content steer therm -rf. The in-code rationale for rejecting mktemp (that an assignment would die inside a command-substitution subshell) does not apply at source time: these variables are assigned when lib.sh is sourced in the main shell, where a mktemp'd path would be equally visible to every subshell; the only real trade-off is the documented lazy-creation/no-stray-file property. Consider a mktemp'd per-process registry directory created at source time (fixed filenames inside, created lazily), which keeps laziness for the files while removing name predictability. Flagged ask-user because the current scheme is explicitly documented as deliberate.bin/fm-watch-arm.sh:418- A commit scopedtest(watcher):changes production behavior in bin/fm-watch-arm.sh: the arm now prints its finished child's output (and deletes the temp file) before spending the successor-confirmation window, so the child's stand-down explanation surfaces up to FM_ARM_CONFIRM_TIMEOUT seconds earlier. I verified the change is safe (wait_for_healthy_successor/healthy_watcher never read child/child_out; the signal handler behaves identically since the child is already reaped on this path; relative stdout order and cycle-ledger timing are unchanged) and it is load-bearing for the new durable-file synchronization in test_arm_waits_for_peer_beacon_after_child_stands_down, which greps the arm's own output for the stand-down line before the beacon exists. Only noting that the commit-type label understates a production output-timing change.🔧 Fix: harden test registries with private mktemp dir
1 info still open:
tests/lib.sh:85- The round-1 hardening makes the registry directory eager: sourcing tests/lib.sh now always runsmktemp -d(tests/lib.sh:85), so any suite that sources lib.sh but overrides the EXIT trap without calling fm_test_cleanup leaks one small empty registry dir per run. Exactly three suites do this: tests/fm-tmux-submit-busy.test.sh (trap 'rm -rf "$TMP_ROOT"' EXIT), tests/fm-afk-pi-herdr-return-e2e.test.sh (custom cleanup that rm -rfs its own TMP_ROOT but never drains the registries — it already leaked the lazy cleanup-log file under the previous commit since it uses fm_test_tmproot), and tests/fm-send-secondmate-marker-herdr-e2e.test.sh. All three violate the trap convention this branch documents in lib.sh and CONTRIBUTING.md, and the leak is bounded to a tiny OS-reaped tmp dir. Making their traps call fm_test_cleanup is a mechanical follow-up, but it would expand this focused upstream-contribution branch to unrelated suites — asking rather than auto-fixing; deferring entirely is also reasonable.🔧 Fix: drain test registries in suites with custom EXIT traps
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bin/fm-test-run.sh tests/fm-watcher-lock.test.sh×3 consecutive runs — 28/28 ok each, exit=0, including the suite's built-in no-leaked-process/no-held-lock audit casebin/fm-test-run.sh tests/fm-tmux-submit-busy.test.sh tests/fm-afk-pi-herdr-return-e2e.test.sh tests/fm-send-secondmate-marker-herdr-e2e.test.sh— tmux suite 4/4 ok; both herdr e2e suites self-skip cleanly behind their opt-in env gates with the new fm_test_cleanup trap line in placeFail-path leak demo: real fm-watch-arm.sh + watcher grandchild registered via fm_test_track_pid, aborted mid-case with fail() — verified both pids reaped, temp home watcher lock released, and suite output pipe reached EOF in 5sPre-change contrast demo (untracked pid, dirs-only EXIT trap) — reproduced the old symptom: output pipe held 76s past the abort by lingering arm/watcher before driver cleanupLeak audit: diffed TMPDIR fm-* dirs and fm-watch/fm-watch-arm processes before vs after all runs — zero suite leftovers, TMPDIR restored to exact baseline, user's real-home watcher untouchedReviewed CONTRIBUTING.md diff — two convention sentences appended after upstream's intact fm-test-run.sh testing-docs section✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.