He-Pin opened a new pull request, #3268:
URL: https://github.com/apache/pekko/pull/3268

   ### Motivation
   
   `StubbedActorContext.scheduleOnce` returned a `Cancellable` with 
`isCancelled = true` and `cancel() = false`, i.e., it was pre-cancelled. This 
violates the `Cancellable` contract (`Scheduler.scala:458-472`):
   
   - `isCancelled`: "Returns true **if and only if** this Cancellable has been 
successfully cancelled"
   - `cancel()`: "Returns true if cancellation was successful; false if already 
cancelled"
   
   A freshly scheduled task has NOT been cancelled, so `isCancelled` should 
start as `false`. The real implementation in `ActorContextAdapter` delegates to 
the real scheduler and returns a genuine `Cancellable` where `isCancelled` 
starts as `false`, causing test/production divergence.
   
   ### Modification
   
   Replace the pre-cancelled `Cancellable` stub in 
`StubbedActorContext.scheduleOnce` with one that starts non-cancelled and 
supports proper cancellation semantics:
   
   ```scala
   new classic.Cancellable {
     private var _cancelled = false
     override def cancel(): Boolean = {
       if (!_cancelled) { _cancelled = true; true } else false
     }
     override def isCancelled: Boolean = _cancelled
   }
   ```
   
   ### Result
   
   `StubbedActorContext.scheduleOnce` now returns a `Cancellable` that matches 
the `Cancellable` contract and the real production implementation behavior. 
Actors that check `cancellable.isCancelled` will now behave consistently in 
tests and production.
   
   ### Tests
   
   - `sbt "actor-testkit-typed / Test / testOnly 
org.apache.pekko.actor.testkit.typed.scaladsl.BehaviorTestKitSpec"` — 35 passed
   - `sbt "actor-testkit-typed / Test / testOnly 
org.apache.pekko.actor.testkit.typed.javadsl.BehaviorTestKitTest"` — 17 passed, 
1 ignored
   
   ### References
   
   Fixes #3251


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