Stabilize flaky waitForNextUpdate hook unit tests #10054
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 522 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.374
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #10054"
general
weight: 0.35
andyatmiami
Fixes: https://issues.redhat.com/browse/RHOAIENG-97653
Problem
Hook unit tests that call
waitForNextUpdate()intermittently assert stale state under full-workspace / contended runs. The hook under test has already rendered the next value (including error paths), but assertions on RTL’sresult.currentstill see the previous (often initial) value — e.g.error: undefinedwhen the wrapper already produced an error.Root timing gap: the helper treated a render-phase counter bump as “update ready,” while
@testing-library/reactonly assignsresult.currentin a post-commituseEffect. Under load,waitForNextUpdatecan resolve in that window, so callers race RTL’s publish. An audit tied this to dozens ofwaitForNextUpdatecall sites across the dashboard and feature packages (see RHOAIENG-97653).A naive fix that also required
result.current === currentResult(or “not the value at wait start”) is too strict or too loose for hooks that return a new array/object identity every render (e.g. FetchState-style tuples), which is why those alternatives were abandoned.User / product impact
No user-visible product behavior change. Impact is on developers and CI:
waitForNextUpdateshould stop flaking on staleresult.current.renderHookfix is duplicated into each in-scope package/distributiontestUtils/hooks.tscopy (not re-exported from jest-config).getUpdateCount()remains render-phase (unchanged semantics for existinghookToHaveUpdateCountassertions).packages//upstream/are intentionally untouched (separate sync).Solution
Canonical fix in
@odh-dashboard/jest-configrenderHook:1. Keep
updateCountfor render-phase / matcher use.2. Add
publishedCount, advanced only when the helper has written the rendered value onto RTL’sresultref (post-commit).3. In a
useEffect, stage the rendered value andflushPublish()once the RTL result ref is available — writeresult.currentbefore bumpingpublishedCount, sowaitForNextUpdatenever resolves on a lagging ref. (Our effect runs before RTL’s; RTL then writes the same value again.)4.
waitForNextUpdatewaits onpublishedCount > expectedvia RTLwaitFor(not on updateCount or result identity).5. Pending publish state is held in a
const deferredobject (resultRef+ boxed{ value }unpublished) so legitimatenull/undefinedresults are not confused with “nothing pending,” andprefer-const/ es2021Errorconstructor constraints are satisfied (no{ cause }options object).Package copies: apply the exact same
renderHooklogic (including theReactimport) to each in-scopefrontend/src/__tests__/unit/testUtils/hooks.ts— agent-ops, automl, autorag, data-connect-hub, data-registry, eval-hub, gen-ai, maas, mlflow, anddistributions/core-bff. Do not re-export from@odh-dashboard/jest-config; keep local copies so packages stay self-contained. Upstream copies underpackages//upstream/are left unchanged.Tests: extend
hooks.spec.tsfor promise/object/batched/successive updates, FetchState-like identity churn, and fake-timer publish viaact(avoid overlapping wait + timer advance under fake timers).Evidence
Local:
Coverage in
hooks.spec.tsincludes: publish-before-resolve for promise and object updates; batched setState final value; successive async updates; new-array-each-render (FetchState-like); fake-timer act flush / partial delay / interval / multi-update / timeout.[RHOAIENG-97653]: https://redhat.atlassian.net/browse/RHOAIENG-97653?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ