Count distinct entities in TestAdvancedSearch data-API helpers - #4
Open
dmaffitt wants to merge 1 commit into
Open
Count distinct entities in TestAdvancedSearch data-API helpers#4dmaffitt wants to merge 1 commit into
dmaffitt wants to merge 1 commit into
Conversation
The subject/session/scan/qc count assertions compared the stored-search result size against get*CountFromDataApi(), which returned the raw row count of the /subjects and /experiments listings. Those listings fan out one row per accessible project membership, so any subject/session shared into another project (including the shared subjects this test creates in addTestProjects) is counted multiple times, while the stored searches return DISTINCT entities. This made testSubjectSearch and testSubjectJoinSearch fail (e.g. 66 vs 64) whenever shared data was visible -- not a server regression but a test-side cardinality mismatch. Rework all four get*CountFromDataApi() helpers to count distinct identities via shared dataApiRows()/distinctRowCount() helpers (subject/session/qc key on ID; scan keys on session-id + scan-id), so the counts are comparable to the DISTINCT searches regardless of sharing or pre-existing data. Verified against a live server: testSubjectSearch and testSubjectJoinSearch now pass. Note: testScanSearch remains failing due to a separate mrScanData search-vs-/experiments-listing visibility discrepancy, not addressed here. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
dmaffitt
marked this pull request as ready for review
August 10, 2026 18:46
rherrick
approved these changes
Aug 11, 2026
ian-xnatworks
approved these changes
Aug 11, 2026
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.
This change hardens TestAdvancedSearch so it can take into account pre-existing data. This surfaced while running tests on the tomcat10-compatible XNAT.
Problem
TestAdvancedSearch.testSubjectSearchandtestSubjectJoinSearchfail with count mismatches (e.g.expected:<66> but was:<64>) whenever any subject visible to the test user is shared into another project — including the shared subjects this test itself creates inaddTestProjects().Root cause: the count assertions compare the stored-search result size against
get*CountFromDataApi(), which returned the raw row count of the/subjectsand/experimentsdata-API listings. Those listings fan out one row per accessible project membership, so a shared subject/session is counted multiple times, while the stored searches return DISTINCT entities. The two cardinalities are therefore only equal on a pristine, share-free server. This is a test-side cardinality mismatch, not a server regression.Relationship to the earlier hardening commit
This is the same fragility the earlier commit 8877213 "Make TestAdvancedSearch more resilient to pre-existing data" set out to fix — and it got the label assertions right by switching exact-equality to
assertContainsAll(...)subset checks (those still pass). But for the counts it replacedassertEquals(subjectLabels.size(), results.size())(own-object count) withassertEquals(getSubjectCountFromDataApi(), results.size())(data-API row count). That made the counts robust to pre-existing data (both endpoints see it) but newly fragile to sharing fan-out, because/data/subjectsfans out per membership while the search is DISTINCT. In other words, 8877213 hardened the subset checks but left the count checks comparing two endpoints with different cardinality semantics. This PR completes that work.Fix
Rework all four
get*CountFromDataApi()helpers to count distinct identities via shareddataApiRows()/distinctRowCount()helpers:ID(xnat:mrsessiondata/id, scan/id)This keeps the "compare against current global server state" intent of 8877213 while making the counts comparable to the DISTINCT searches regardless of sharing or leftover data.
Verification
Ran
-Dtest=TestAdvancedSearchagainst a live server:testSubjectSearchandtestSubjectJoinSearchnow pass (class failures 3 → 1). Compiles under JDK 8.