He-Pin opened a new issue, #3242:
URL: https://github.com/apache/pekko/issues/3242

   ### Description
   
   `ManualTime.expectNoMessageFor` calls `expectNoMessage(Duration.Zero)` on 
each probe after advancing simulated time. The zero-duration call triggers a 
non-blocking `queue.pollFirst()` in `TestProbeImpl.receiveOne_internal`, which 
can miss messages that were scheduled by `timePasses` but haven't been 
delivered to the probe's mailbox yet.
   
   ### Affected code
   
   
`actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/scaladsl/ManualTime.scala`
 (lines 75-79):
   
   ```scala
   def expectNoMessageFor(duration: FiniteDuration, on: TestProbe[?]*): Unit = {
     delegate.timePasses(duration)
     on.foreach(_.expectNoMessage(Duration.Zero))  // non-blocking poll
   }
   ```
   
   In `TestProbeImpl.receiveOne_internal` (lines 201-206):
   
   ```scala
   private def receiveOne_internal(max: FiniteDuration): Option[M] = {
     val message = Option(if (max == Duration.Zero) {
       queue.pollFirst        // non-blocking; misses in-flight messages
     } else {
       queue.pollFirst(max.length, max.unit)
     })
   }
   ```
   
   ### Impact
   
   Messages dispatched during `timePasses` may not yet be in the probe's queue 
when the non-blocking poll runs, causing false-negative test results (test 
passes when it should fail).
   
   ### Suggested fix
   
   Replace `Duration.Zero` with the no-arg `expectNoMessage()` which uses 
`ExpectNoMessageDefaultTimeout` (dilated, typically 100ms x TestTimeFactor), 
giving scheduled deliveries time to reach the probe's mailbox:
   
   ```scala
   on.foreach(_.expectNoMessage())  // uses default timeout with dilation
   ```
   
   The same change should be applied to the Java DSL counterpart in 
`javadsl/ManualTime.scala`.


-- 
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]

Reply via email to