Skip to content

Commit a128a2e

Browse files
committed
test: assert the query count does not grow, instead of exact equality
dataElementCountDoesNotScaleQueryCount compares a metadata export with 3 data elements against one with 8 and asserted the two select counts were equal. With the cache changes in this branch the second export legitimately issues FEWER selects (21 vs 22): what the first export loaded is still cached during the second. Assert the invariant the test name and comment state - the count must not grow - so the test keeps catching a reintroduced N+1 without failing on a cache improvement. AI Assisted
1 parent 5c5d155 commit a128a2e

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/metadata/DataSetMetadataExportServiceQueryCountTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,15 @@ void dataElementCountDoesNotScaleQueryCount() {
115115
// DataElement / DataSetElement loads are batched into a single query, so the select count must
116116
// not grow with the number of data elements. If it does, the N+1 has been reintroduced (e.g. by
117117
// iterating DataSet.getDataElements() or DataElement.getCategoryCombos() lazily).
118-
assertEquals(
119-
baseline,
120-
withMoreDataElements,
121-
"adding data elements must not increase the number of SQL selects");
118+
// The count may legitimately DROP between the two measurements: whatever the first export
119+
// loaded can still be served from the second level cache during the second one, so this
120+
// asserts the invariant the test name states (no growth) rather than exact equality.
121+
assertTrue(
122+
withMoreDataElements <= baseline,
123+
"adding data elements must not increase the number of SQL selects: "
124+
+ baseline
125+
+ " -> "
126+
+ withMoreDataElements);
122127
}
123128

124129
@Test

0 commit comments

Comments
 (0)