Merge pull request #16396 from kustosz/cancel-state-timeout-after-stopping-actor
=act #13894 cancel StateTimeout when FSM actor is stopped
This commit is contained in:
commit
49d9082851
2 changed files with 21 additions and 0 deletions
|
|
@ -45,6 +45,15 @@ class FSMTimingSpec extends AkkaSpec with ImplicitSender {
|
|||
}
|
||||
}
|
||||
|
||||
"cancel a StateTimeout when actor is stopped" taggedAs TimingTest in {
|
||||
val stoppingActor = system.actorOf(Props[StoppingActor])
|
||||
system.eventStream.subscribe(testActor, classOf[DeadLetter])
|
||||
stoppingActor ! TestStoppingActorStateTimeout
|
||||
within(400 millis) {
|
||||
expectNoMsg
|
||||
}
|
||||
}
|
||||
|
||||
"allow StateTimeout override" taggedAs TimingTest in {
|
||||
// the timeout in state TestStateTimeout is 800 ms, then it will change to Initial
|
||||
within(400 millis) {
|
||||
|
|
@ -164,6 +173,7 @@ object FSMTimingSpec {
|
|||
case object TestCancelTimer extends State
|
||||
case object TestCancelStateTimerInNamedTimerMessage extends State
|
||||
case object TestCancelStateTimerInNamedTimerMessage2 extends State
|
||||
case object TestStoppingActorStateTimeout extends State
|
||||
|
||||
case object Tick
|
||||
case object Tock
|
||||
|
|
@ -266,5 +276,15 @@ object FSMTimingSpec {
|
|||
}
|
||||
}
|
||||
|
||||
class StoppingActor extends Actor with FSM[State, Int] {
|
||||
startWith(Initial, 0)
|
||||
|
||||
when(Initial, 200 millis) {
|
||||
case Event(TestStoppingActorStateTimeout, _) ⇒
|
||||
context.stop(self)
|
||||
stay
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -682,6 +682,7 @@ trait FSM[S, D] extends Actor with Listeners with ActorLogging {
|
|||
logTermination(reason)
|
||||
for (timer ← timers.values) timer.cancel()
|
||||
timers.clear()
|
||||
timeoutFuture.foreach { _.cancel() }
|
||||
currentState = nextState
|
||||
|
||||
val stopEvent = StopEvent(reason, currentState.stateName, currentState.stateData)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue