Skip to content

test: stabilize QueryVirtualStorageTest metric assertions - #19886

Open
FrankChen021 wants to merge 3 commits into
apache:masterfrom
FrankChen021:codex/stabilize-query-virtual-storage-test
Open

test: stabilize QueryVirtualStorageTest metric assertions#19886
FrankChen021 wants to merge 3 commits into
apache:masterfrom
FrankChen021:codex/stabilize-query-virtual-storage-test

Conversation

@FrankChen021

Copy link
Copy Markdown
Member

Summary

  • Stabilize the cumulative virtual storage metric assertions in QueryVirtualStorageTest.testQueryPartials.
  • Replace race-prone waitForNextEvent calls with LatchableEmitter.waitForEventAggregate waits where the test reads cumulative metric totals.
  • Preserve the existing metric thresholds and avoid sleeps, timeout increases, or weakened assertions.

Root cause

StorageMonitor emits virtual storage metrics on periodic monitor ticks and resets the interval statistics after each tick. The test previously waited for only one future matching event with waitForNextEvent, then read a cumulative total. If that event represented an interval before the final segment load completed, the test could observe 23 loads even though a later metric event would bring the cumulative total to the required 24.

waitForEventAggregate evaluates already-processed matching events and continues collecting future matching events until the requested cumulative threshold is reached. The fix therefore removes the timing race while retaining the expected thresholds.

Evidence

This is a test-stability fix found while validating the JUnit 5 migration. It does not migrate JUnit, change production behavior, or change the expected metric thresholds. Related to #13948.

Validation

  • mvn -ntp test -pl embedded-tests -am -Dtest="org.apache.druid.testing.embedded.query.QueryVirtualStorageTest#testQueryPartials" -Dsurefire.failIfNoSpecifiedTests=false -Pskip-static-checks -Dweb.console.skip=true -T1C — 1 test, 0 failures, 0 errors, 0 skipped; full reactor BUILD SUCCESS.
  • mvn -ntp -pl embedded-tests -am -DskipTests -Dweb.console.skip=true -Dcheckstyle.skip=false -Dspotbugs.skip=false checkstyle:check spotbugs:check -T1CBUILD SUCCESS; Checkstyle reported 0 violations and SpotBugs reported no bugs/errors.
  • git diff --check — passed.

@FrankChen021
FrankChen021 marked this pull request as ready for review August 5, 2026 02:21
Copilot AI lite review requested due to automatic review settings August 5, 2026 02:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR stabilizes QueryVirtualStorageTest.testQueryPartials by replacing race-prone “wait for one next event” latches with aggregate-based waits when asserting cumulative virtual storage metrics, aligning the waiting strategy with how StorageMonitor emits and resets interval stats.

Changes:

  • Replaced LatchableEmitter.waitForNextEvent waits with LatchableEmitter.waitForEventAggregate for cumulative metric thresholds (e.g., load begin count, hit count).
  • Added aggregate waits for several additional VSF metrics before reading cumulative sums to reduce timing-related flakes.
Suppressed comments (1)

embedded-tests/src/test/java/org/apache/druid/testing/embedded/query/QueryVirtualStorageTest.java:276

  • Similar to the read metrics, StorageMonitor emits VSF_EVICT_COUNT and VSF_EVICT_BYTES as separate events. Waiting only for VSF_EVICT_COUNT can release before the bytes event is processed, making the immediate VSF_EVICT_BYTES > 0 assertion flaky. Add an aggregate wait for VSF_EVICT_BYTES before asserting.
        event -> event.hasMetricName(StorageMonitor.VSF_EVICT_COUNT),
        aggregate -> aggregate.hasSumAtLeast(1)
    );
    Assertions.assertTrue(emitter.getMetricEventLongSum(StorageMonitor.VSF_EVICT_COUNT) > 0);
    Assertions.assertTrue(emitter.getMetricEventLongSum(StorageMonitor.VSF_EVICT_BYTES) > 0);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity Findings
P0 0
P1 0
P2 1
P3 0
Total 1
Severity Findings
P0 0
P1 0
P2 1
P3 0
Total 1

Reviewed 1 of 1 changed files.


This is an automated review by Codex GPT-5.6-Sol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants