This is an automated email from the ASF dual-hosted git repository.

He-Pin pushed a commit to branch stabilize-flaky-resizer-autocloseable
in repository https://gitbox.apache.org/repos/asf/pekko.git

commit 3f7738752a11b133c7a8e406930d6a274c362796
Author: He-Pin <[email protected]>
AuthorDate: Sat May 9 18:12:01 2026 +0800

    test: stabilize resizer performance log sampling
    
    Motivation:
    The "record the performance log with the correct pool size" test in
    MetricsBasedResizerSpec is intermittently flaky on JDK21+/JDK25 nightly
    runs (e.g. apache/pekko#25586760215, ~12s before failing on JDK 25 /
    Scala 2.13.x with virtualized dispatchers). Between the two
    reportMessageCount checkpoints the test sent only one extra mockSend
    per routee. With virtual-thread scheduling those extra messages can be
    processed before the second reportMessageCount runs, leaving routees
    idle (currentMessage = null) so messagesInRoutees underestimates the
    queue and the resizer's fullyUtilized check falls through, no
    performance log is recorded, and the final assertion fails with
    "None was empty".
    
    Modification:
    Replace the inter-checkpoint mockSend pair with a second sendToAll
    call (await=false) and Await.ready on its first latch. This keeps both
    routees actively holding their currentMessage when reportMessageCount
    runs, so the resizer always observes the routees as fully utilized
    across the two checkpoints.
    
    Result:
    The test no longer relies on routees still being busy by chance after
    their previous batch completes, and runs deterministically on
    virtualized dispatchers.
---
 .../org/apache/pekko/routing/MetricsBasedResizerSpec.scala    | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

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 984725d17d..59752e01b4 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
@@ -235,15 +235,12 @@ class MetricsBasedResizerSpec extends 
PekkoSpec(ResizerSpec.config) with Default
     "record the performance log with the correct pool size" in {
       val resizer = DefaultOptimalSizeExploringResizer()
       val router = TestRouter(routees(2))
-      val msgs = router.sendToAll(await = true)
+      val msgs1 = router.sendToAll(await = true)
+      val msgs2 = router.sendToAll(await = false)
       resizer.reportMessageCount(router.routees, router.msgs.size)
-      msgs.head.second.open()
+      msgs1.head.second.open()
 
-      router.mockSend(await = true, routeeIdx = 0)
-      router.mockSend(await = false, routeeIdx = 1)
-      awaitAssert {
-        resizer.updatedStats(router.routees, router.msgs.size)._1.get(2) 
should not be empty
-      }
+      Await.ready(msgs2.head.first, timeout.duration)
       resizer.reportMessageCount(router.routees, router.msgs.size)
       resizer.performanceLog.get(2) should not be empty
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to