This is an automated email from the ASF dual-hosted git repository. hepin pushed a commit to branch flasky_java21 in repository https://gitbox.apache.org/repos/asf/pekko.git
commit 7f04fcbe198b2c0d0a309549a59cedefdda154ea Author: He-Pin <[email protected]> AuthorDate: Sun Mar 22 18:34:11 2026 +0800 chore: fix flasky test in MetricsBasedResizerSpec Fix Summary **Problem:** The test case "must update the underutilizationStreak highestUtilization if current utilization is higher" within `MetricsBasedResizerSpec` was failing intermittently on CI; the expected `highestUtilization` value was 2, but the actual value was 1. **Root Cause:** A race condition. The test sends one message each to `routee 0` and `routee 1`, followed by an `await` call; however, the `await` only guarantees that the actors have *begun* processing the messages (specifically, that `first.countDown()` has been invoked). When `reportMessageCount` checks `cell.currentMessage` and `mailbox.numberOfMessages`, a very brief time window may exist—particularly under the high load conditions of the CI environment—during which a specific rou [...] **Fix:** After the initial `mockSend(await = true)` calls, an additional `mockSend(await = false)` message is now sent to both `routee 0` and `routee 1`. This ensures that, even if the `currentMessage` state is momentarily indeterminate, there remain pending messages within the mailbox (i.e., `numberOfMessages > 0`), thereby guaranteeing the correct calculation of the `utilized` metric. This approach aligns with the pattern utilized by other tests within the same test file (e.g., the [...] --- .../scala/org/apache/pekko/routing/MetricsBasedResizerSpec.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/actor-tests/src/test/scala/org/apache/pekko/routing/MetricsBasedResizerSpec.scala b/actor-tests/src/test/scala/org/apache/pekko/routing/MetricsBasedResizerSpec.scala index 0c930e491e..3642c07a3d 100644 --- a/actor-tests/src/test/scala/org/apache/pekko/routing/MetricsBasedResizerSpec.scala +++ b/actor-tests/src/test/scala/org/apache/pekko/routing/MetricsBasedResizerSpec.scala @@ -187,8 +187,13 @@ class MetricsBasedResizerSpec extends PekkoSpec(ResizerSpec.config) with Default underutilizationStreak = Some(UnderUtilizationStreak(start = LocalDateTime.now, highestUtilization = 1))) val router = TestRouter(routees(3)) + // Send messages to routee 0 and 1, await ensures the actor started processing router.mockSend(await = true, routeeIdx = 0) router.mockSend(await = true, routeeIdx = 1) + // Send additional messages to ensure mailbox is non-empty when checked, + // avoiding a race condition where currentMessage could be null momentarily + router.mockSend(await = false, routeeIdx = 0) + router.mockSend(await = false, routeeIdx = 1) resizer.reportMessageCount(router.routees, router.msgs.size) resizer.record.underutilizationStreak.get.highestUtilization shouldBe 2 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
