test: de-flake ItemHandleCheckerIT (mock the live handle resolver)#1346
test: de-flake ItemHandleCheckerIT (mock the live handle resolver)#1346milanmajchrak wants to merge 2 commits into
Conversation
ItemHandleCheckerIT.testItemHandleNotFound intermittently failed on dtq-dev with a synthetic 617 (SocketTimeoutException) instead of 404. The checkhandles task (ItemHandleChecker) issues a HEAD request to each item's handle URL (handle.canonical.prefix + handle) with a 3s read timeout; the test pointed the prefix at the live http://hdl.handle.net/ and asserted the resolver returns 404 (non-existent handle) and 302->200 (a real handle). When the live resolver was slow/unreachable the HEAD timed out -> 617 -> red pipeline. Same class of flake as the ORCID tests; not a regression (the merge commit passed many other runs). Fix (test-only): serve the handle URLs from a local okhttp3 MockWebServer. setUp sets handle.canonical.prefix to the mock base URL; a path-based dispatcher returns 302 (+Location to a -target path) for the redirect handle, 200 for the target, and 404 otherwise. The real/invalid/ignored URLs are derived from the mock base instead of hard-coded hdl.handle.net literals; the server is closed in @after. All six tests keep their original assertions and behavior; only the live-network hop is removed. Verified locally: 6/6 green across 4 runs, no external network involved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 22 minutes and 56 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughItemHandleCheckerIT now runs handle resolution tests against a local MockWebServer, computes mock-based handle URLs from its dynamic port, updates the test cases to use those URLs, and closes the mock server during teardown. ChangesMocked handle resolution tests
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@dspace-api/src/test/java/org/dspace/curate/ItemHandleCheckerIT.java`:
- Around line 97-128: The test setup in ItemHandleCheckerIT mutates the shared
cfg property handle.canonical.prefix to point at the mock MockWebServer, but
never restores the original value after the test finishes. Capture the previous
handle.canonical.prefix before setUp changes it, then restore it in the
corresponding teardown/cleanup path for ItemHandleCheckerIT so later tests are
not left pointing at a dead localhost server.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 25e86edd-81a9-46b7-bc41-bb7214f63d6b
📒 Files selected for processing (1)
dspace-api/src/test/java/org/dspace/curate/ItemHandleCheckerIT.java
Address CodeRabbit: setUp overwrites the shared handle.canonical.prefix with the per-run mock-server URL. Capture the previous value and restore it in destroy() (after closing the mock server) so a later test in the same JVM is never left pointing at the now-closed localhost port. (The superclass destroy() reloadConfig() already resets it, but restoring explicitly makes the test self-contained.) Re-verified locally: 6/6 green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Why
After #1344 merged, a scheduled
dtq-devbuild went red onItemHandleCheckerIT.testItemHandleNotFound:This is not a regression from #1344 — the same merge commit passed 5 subsequent scheduled runs. It's a
separate, pre-existing flaky test (the 5th de-flaked so far), in the same family as the ORCID one: a live
network dependency.
Root cause
The
checkhandlescuration task (ItemHandleChecker) issues a JAX-RS HEAD request to each item's handleURL (
handle.canonical.prefix+ handle) with a 3-second read timeout; on timeout it reports a syntheticstatus 617. The test set
handle.canonical.prefix = http://hdl.handle.net/and asserted that the liveresolver returns
404for a non-existent handle (testItemHandleNotFound) and302 → 200for a real handle(
testItemHandleRedirected, andtestCurateCollection). Wheneverhdl.handle.netwas slow/unreachable fromthe CI runner, the HEAD timed out →
617instead of the expected status → red pipeline.Fix (test-only — no production change)
Serve the handle URLs from a local
okhttp3.mockwebserver.MockWebServerinstead of the live resolver:setUp()starts the mock server and setshandle.canonical.prefixto its base URL, so item canonical URLsresolve to
http://localhost:<port>/....Dispatcherreturns deterministic responses:302(with aLocationto a-targetpath) forthe "real" redirect handle,
200for the redirect target, and404for any other (well-formed) handle URL.hdl.handle.netliterals; the mock is closed in
@After.This keeps all six tests and their assertions exactly as before (404, 302→200, no-item-fail,
client-side
URISyntaxException→500, ignore-list skip, and the mixed-collection case) — it only removes thenon-deterministic network hop. No production code changed.
Verification
Run locally against the dspace-api IT harness 4×, all green (
Tests run: 6, Failures: 0, Errors: 0), withno external network involved (everything goes to loopback). Reviewed by a senior Java/Spring pass.
Summary by CodeRabbit