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

hepin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git


The following commit(s) were added to refs/heads/main by this push:
     new 7fef63392e Fix EventSourcedBehaviorStashSpec flaky failures (#2804)
7fef63392e is described below

commit 7fef63392e36504093f677863e866e3f8bf6fe45
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Sat Mar 28 17:01:38 2026 +0800

    Fix EventSourcedBehaviorStashSpec flaky failures (#2804)
    
    Multiple fixes for test flakiness:
    
    - Increase timeout from 5s to 10s for concurrent stash operations that
      produce many events, giving the system enough time under load.
    - Change StashLimit.customStashLimit from val to def for proper trait
      initialization order.
    - Add thenRun callback to 'start-stashing' persist to confirm write
      completion before sending more commands, preventing race conditions
      where commands are auto-stashed by ESB instead of user stash.
    - Wait for 'started-stashing' confirmation in both stash limit tests
      before flooding with commands.
    
    Upstream: akka/akka-core@1c9b1b4116
    Cherry-picked from akka/akka-core v2.8.0, which is now Apache licensed.
---
 .../typed/scaladsl/EventSourcedBehaviorStashSpec.scala  | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git 
a/persistence-typed-tests/src/test/scala/org/apache/pekko/persistence/typed/scaladsl/EventSourcedBehaviorStashSpec.scala
 
b/persistence-typed-tests/src/test/scala/org/apache/pekko/persistence/typed/scaladsl/EventSourcedBehaviorStashSpec.scala
index 6ca4190281..dd85814d55 100644
--- 
a/persistence-typed-tests/src/test/scala/org/apache/pekko/persistence/typed/scaladsl/EventSourcedBehaviorStashSpec.scala
+++ 
b/persistence-typed-tests/src/test/scala/org/apache/pekko/persistence/typed/scaladsl/EventSourcedBehaviorStashSpec.scala
@@ -338,9 +338,10 @@ class EventSourcedBehaviorStashSpec
 
       unhandledProbe.receiveMessages(10)
 
-      val value1 = stateProbe.expectMessageType[State](5.seconds).value
-      val value2 = stateProbe.expectMessageType[State](5.seconds).value
-      val value3 = stateProbe.expectMessageType[State](5.seconds).value
+      // a lot of events, so give it some extra time to complete
+      val value1 = stateProbe.expectMessageType[State](10.seconds).value
+      val value2 = stateProbe.expectMessageType[State](10.seconds).value
+      val value3 = stateProbe.expectMessageType[State](10.seconds).value
 
       // verify the order
 
@@ -541,7 +542,7 @@ class EventSourcedBehaviorStashSpec
     }
 
     trait StashLimit {
-      val customStashLimit: Option[Int] = None
+      def customStashLimit: Option[Int]
       val probe = TestProbe[AnyRef]()
       system.toClassic.eventStream.subscribe(probe.ref.toClassic, 
classOf[Dropped])
       val behavior = Behaviors.setup[String] { context =>
@@ -556,7 +557,7 @@ class EventSourcedBehaviorStashSpec
                     probe.ref ! "pong"
                     Effect.none
                   case "start-stashing" =>
-                    Effect.persist("start-stashing")
+                    Effect.persist("start-stashing").thenRun(_ => probe ! 
"started-stashing")
                   case msg =>
                     probe.ref ! msg
                     Effect.none
@@ -585,7 +586,7 @@ class EventSourcedBehaviorStashSpec
     }
 
     "discard when stash has reached limit with default dropped setting" in new 
StashLimit {
-
+      override val customStashLimit: Option[Int] = None
       val c = spawn(behavior)
 
       // make sure it completed recovery, before we try to overfill the stash
@@ -593,6 +594,8 @@ class EventSourcedBehaviorStashSpec
       probe.expectMessage("pong")
 
       c ! "start-stashing"
+      // make sure write completes before sending more commands so that they 
are not auto-stashed by ESB
+      probe.expectMessage("started-stashing")
 
       val limit = 
system.settings.config.getInt("pekko.persistence.typed.stash-capacity")
       LoggingTestKit.warn("Stash buffer is full, dropping message").expect {
@@ -624,6 +627,8 @@ class EventSourcedBehaviorStashSpec
       probe.expectMessage("pong")
 
       c ! "start-stashing"
+      // make sure write completes before sending more commands so that they 
are not auto-stashed by ESB
+      probe.expectMessage("started-stashing")
 
       LoggingTestKit.warn("Stash buffer is full, dropping message").expect {
         (0 to customLimit).foreach { n =>


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

Reply via email to