fix bug in FSM when manually rescheduling non-recurring timer, see #2043

cherry-picked from 0314b9abbb plus test
case written
This commit is contained in:
Roland 2012-05-04 22:30:00 +02:00
parent 194527fba1
commit bab18af92c
2 changed files with 23 additions and 3 deletions

View file

@ -67,6 +67,18 @@ class FSMTimingSpec extends AkkaSpec with ImplicitSender {
}
}
"resubmit single-shot timer" taggedAs TimingTest in {
within(2 seconds) {
within(500 millis, 1.5 second) {
fsm ! TestSingleTimerResubmit
expectMsg(Tick)
expectMsg(Tock)
expectMsg(Transition(fsm, TestSingleTimerResubmit, Initial))
}
expectNoMsg
}
}
"correctly cancel a named timer" taggedAs TimingTest in {
fsm ! TestCancelTimer
within(500 millis) {
@ -106,8 +118,8 @@ class FSMTimingSpec extends AkkaSpec with ImplicitSender {
}
"notify unhandled messages" taggedAs TimingTest in {
filterEvents(EventFilter.warning("unhandled event Tick in state TestUnhandled", source = fsm.toString, occurrences = 1),
EventFilter.warning("unhandled event Unhandled(test) in state TestUnhandled", source = fsm.toString, occurrences = 1)) {
filterEvents(EventFilter.warning("unhandled event Tick in state TestUnhandled", source = fsm.path.toString, occurrences = 1),
EventFilter.warning("unhandled event Unhandled(test) in state TestUnhandled", source = fsm.path.toString, occurrences = 1)) {
fsm ! TestUnhandled
within(1 second) {
fsm ! Tick
@ -142,6 +154,7 @@ object FSMTimingSpec {
case object TestStateTimeout extends State
case object TestStateTimeoutOverride extends State
case object TestSingleTimer extends State
case object TestSingleTimerResubmit extends State
case object TestRepeatedTimer extends State
case object TestUnhandled extends State
case object TestCancelTimer extends State
@ -179,6 +192,13 @@ object FSMTimingSpec {
tester ! Tick
goto(Initial)
}
onTransition {
case Initial -> TestSingleTimerResubmit setTimer("blah", Tick, 500 millis, false)
}
when(TestSingleTimerResubmit) {
case Event(Tick, _) tester ! Tick; setTimer("blah", Tock, 500 millis, false)
case Event(Tock, _) tester ! Tock; goto(Initial)
}
when(TestCancelTimer) {
case Event(Tick, _)
setTimer("hallo", Tock, 1 milli, false)

View file

@ -443,10 +443,10 @@ trait FSM[S, D] extends Listeners {
timeoutFuture = None
}
generation += 1
processMsg(msg, t)
if (!repeat) {
timers -= name
}
processMsg(msg, t)
}
case SubscribeTransitionCallBack(actorRef)
// TODO use DeathWatch to clean up list