Repository navigation
useDeepLinkテストのナビゲーションリトライタイマーのリークを断ちpreset無視テストのflakyを解消 - #6645
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01H5CNFjS7EbqWAU6hXqFwUC
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesDeep link テストの安定化
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
src/hooks/useDeepLink.test.tsxのpreset (ホーム画面ウィジェット) › UUID形式でないpresetは無視するがフルスイート実行時にまれに失敗する問題(#6607)を解消します。原因はテスト間の非同期リークであり、製品コードの不具合ではありません。推定ではなく決定的な再現手順を作って原因を確定させました。機序は以下のとおりです。
useDeepLink.tsのwaitForNavReadyは実タイマー(setTimeout100/200/400/800ms)でリトライします。多くのテストはnavigateToMain()に到達したあと、このリトライ列が決着する前に終了するため、コールバックが保留のまま残ります。約 1.5 秒後、そのコールバックは「たまたまその時点で実行中の別テスト」の中で発火し、共有モックであるnavigationRefを参照します。そのテストがisReady()をtrueにスタブしていると(UUID形式でないpresetは無視するがまさにそうです)、リトライ列は準備完了と判断してNAVIGATE → MainStack/Mainを共有dispatchモックへ流し込み、negative assertion を壊します。Issue に記載された「dispatch の型が
RESETではなくNAVIGATEだった」「2 回呼ばれた(=リーク列が 2 本)」という観測は、いずれもこの機序で説明できます。あわせて報告されていたJest did not exit one second after the test run has completed.も同じ保留タイマーが原因で、当該ファイル単独実行でも再現していました。変更の種類
変更内容
テストのみの変更で、製品コードには手を入れていません。
beforeEachでjest.useFakeTimers()を有効化し、waitForNavReadyのリトライ列をフェイクタイマー上に載せました。既存のafterEachは元からjest.clearAllTimers()を呼んでいましたが、実タイマーに対しては破棄できるものが何もありませんでした。フェイクタイマー化によってこの呼び出しが実効化し、テスト境界で保留中のコールバックが確実に破棄されます。継続は未解決のまま放棄されるため、共有モックへ到達できなくなります。afterEachのコメントを、上記の実際の役割に合わせて更新しました。UUID形式でないpresetは無視するの同期点をwaitFor(getInitialURL が呼ばれた)からwaitFor(initialUrlProcessed === true)に強化しました。前者は「effect が始まった」ことしか保証せず、handleUrlの非同期処理が残っている段階で negative assertion が走っていました。後者は effect のfinallyで立つため、ディープリンク処理が一巡したことを表します。補足: 同期点の強化だけでは今回の flaky は直りません。混入源は当該テスト自身ではなく「他のテスト」が残した保留タイマーであるため、根本対処はフェイクタイマー化の側にあります。同期点の強化は、Issue の対応案にも挙がっていた「テスト自身の弱い同期点」を独立に潰すための追加分です。
テスト
npm run lintが通ることnpm testが通ることnpm run typecheckが通ること決定的な再現と、その解消
negative assertion の直前に実時間 1.6 秒の待機を挿入して(フルスイート実行時の負荷を模擬)、
初回URLがある場合にstateを設定するとUUID形式でないpresetは無視するの 2 件だけを実行したところ、Issue と同一の失敗を再現しました。修正後は同じ再現手順で成功します。再現用の待機は本 PR の差分には含めていません。
副次的な改善
npx jest src/hooks/useDeepLink.test.tsx単独実行の前後比較です。Jest did not exit ...警告not wrapped in act警告実行時間の短縮は、実時間で待っていた
waitForのポーリングとリトライ待ちが無くなったためです。実行したコマンド
npm run lint→ 626 files をチェックしクリーンnpm test→ 215 suites / 2277 tests すべて成功、did not exit警告なしnpm run typecheck→ クリーンリグレッションリスクと緩和策
@testing-library/react-nativeのwaitForはフェイクタイマーを検知してjest.advanceTimersByTimeで進める実装(build/wait-for.js)になっており、本ファイルの 40 箇所のwaitForはすべて期待どおり動作します。当該ファイル 82 件、フルスイート 2277 件すべての成功を確認済みです。afterEachのjest.useRealTimers()で必ず戻します(既存の実装を維持)。関連Issue
Closes #6607
スクリーンショット(任意)
UI 変更なし(テストのみの変更)のため添付はありません。
Generated by Claude Code
Summary by CodeRabbit