Copilot commented on code in PR #19886:
URL: https://github.com/apache/druid/pull/19886#discussion_r3717500565
##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/query/QueryVirtualStorageTest.java:
##########
@@ -222,24 +225,53 @@ void testQueryPartials()
expectedTotalHits += (expectedLoads[nextQuery] - actualLoads);
}
- emitter.waitForNextEvent(event ->
event.hasMetricName(StorageMonitor.VSF_HIT_COUNT));
+ final long expectedTotalHitsForWait = expectedTotalHits;
+ emitter.waitForEventAggregate(
+ event -> event.hasMetricName(StorageMonitor.VSF_HIT_COUNT),
+ aggregate -> aggregate.hasSumAtLeast(expectedTotalHitsForWait)
+ );
long hits = emitter.getMetricEventLongSum(StorageMonitor.VSF_HIT_COUNT);
Assertions.assertTrue(hits >= expectedTotalHits, "expected " +
expectedTotalHits + " but only got " + hits);
if (expectedTotalHits > 0) {
- emitter.waitForNextEvent(event ->
event.hasMetricName(StorageMonitor.VSF_HIT_BYTES));
+ emitter.waitForEventAggregate(
+ event -> event.hasMetricName(StorageMonitor.VSF_HIT_BYTES),
+ aggregate -> aggregate.hasSumAtLeast(1)
+ );
Assertions.assertTrue(emitter.getMetricEventLongSum(StorageMonitor.VSF_HIT_BYTES)
> 0);
}
- emitter.waitForNextEvent(event ->
event.hasMetricName(StorageMonitor.VSF_LOAD_BEGIN_COUNT));
+ final long expectedTotalLoadForWait = expectedTotalLoad;
+ emitter.waitForEventAggregate(
+ event -> event.hasMetricName(StorageMonitor.VSF_LOAD_BEGIN_COUNT),
+ aggregate -> aggregate.hasSumAtLeast(expectedTotalLoadForWait)
+ );
long loads =
emitter.getMetricEventLongSum(StorageMonitor.VSF_LOAD_BEGIN_COUNT);
Assertions.assertTrue(loads >= expectedTotalLoad, "expected " +
expectedTotalLoad + " but only got " + loads);
+ emitter.waitForEventAggregate(
+ event -> event.hasMetricName(StorageMonitor.VSF_LOAD_BEGIN_BYTES),
+ aggregate -> aggregate.hasSumAtLeast(1)
+ );
Assertions.assertTrue(emitter.getMetricEventLongSum(StorageMonitor.VSF_LOAD_BEGIN_BYTES)
> 0);
+ emitter.waitForEventAggregate(
+ event -> event.hasMetricName(StorageMonitor.VSF_LOAD_COUNT),
+ aggregate -> aggregate.hasSumAtLeast(1)
+ );
Assertions.assertTrue(emitter.getMetricEventLongSum(StorageMonitor.VSF_LOAD_COUNT)
> 0);
+ emitter.waitForEventAggregate(
+ event -> event.hasMetricName(StorageMonitor.VSF_LOAD_BYTES),
+ aggregate -> aggregate.hasSumAtLeast(1)
+ );
Assertions.assertTrue(emitter.getMetricEventLongSum(StorageMonitor.VSF_LOAD_BYTES)
> 0);
- emitter.waitForNextEvent(event ->
event.hasMetricName(StorageMonitor.VSF_READ_COUNT));
+ emitter.waitForEventAggregate(
+ event -> event.hasMetricName(StorageMonitor.VSF_READ_COUNT),
+ aggregate -> aggregate.hasSumAtLeast(1)
+ );
Assertions.assertTrue(emitter.getMetricEventLongSum(StorageMonitor.VSF_READ_COUNT)
> 0);
Assertions.assertTrue(emitter.getMetricEventLongSum(StorageMonitor.VSF_READ_BYTES)
> 0);
Assertions.assertTrue(emitter.getMetricEventLongSum(StorageMonitor.VSF_READ_TIME)
>= 0);
Review Comment:
`waitForEventAggregate` waits only for `VSF_READ_COUNT`, but
`StorageMonitor` emits `VSF_READ_BYTES` and `VSF_READ_TIME` as separate metric
events after the count event. This can still race: the latch can release on the
count event while bytes hasn’t been emitted yet, making
`getMetricEventLongSum(VSF_READ_BYTES)` transiently 0 and failing the
subsequent assertion. Add an aggregate wait for `VSF_READ_BYTES` (and
optionally `VSF_READ_TIME` via `hasCountAtLeast(1)`) before asserting on those
cumulative sums.
This issue also appears on line 272 of the same file.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]