He-Pin opened a new issue, #3251:
URL: https://github.com/apache/pekko/issues/3251
### Motivation
`StubbedActorContext.scheduleOnce` returns a `Cancellable` with `isCancelled
= true` and `cancel()` returning `false`, i.e., it is pre-cancelled. This
violates the `Cancellable` contract and causes test/production divergence.
### Current Behavior
`StubbedActorContext.scala:162-166`:
```scala
override def scheduleOnce[U](delay: FiniteDuration, target: ActorRef[U],
message: U): classic.Cancellable =
new classic.Cancellable {
override def cancel() = false
override def isCancelled = true
}
```
The `Cancellable` contract (`Scheduler.scala:458-472`) states:
- `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 just-scheduled task has NOT been cancelled, so `isCancelled` should be
`false`.
### Production vs Test Divergence
The real implementation (`ActorContextAdapter.scala:139-141`) delegates to
the real scheduler and returns a genuine `Cancellable` where `isCancelled`
starts as `false`. An actor that checks `cancellable.isCancelled` will take a
different code path in tests vs. production.
### Expected Behavior
Return a `Cancellable` that starts non-cancelled and can be properly
cancelled:
```scala
new classic.Cancellable {
private var _cancelled = false
override def cancel(): Boolean = {
if (!_cancelled) { _cancelled = true; true } else false
}
override def isCancelled: Boolean = _cancelled
}
```
### Environment
- Pekko Actor TestKit Typed (any version)
- `StubbedActorContext.scala:162-166`
### References
None
--
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]