public void FSM_must_allow_StateTimeout_override() { //arrange //act //the timeout in state TestStateTieout is 800ms, then it will change back to Initial Within(TimeSpan.FromMilliseconds(400), () => { fsm.Tell(State.TestStateTimeoutOverride, Self); expectMsg(new FSMBase.Transition <State>(fsm, State.Initial, State.TestStateTimeout), FSMSpecHelpers.TransitionStateExpector <State>()); expectNoMsg(TimeSpan.FromMilliseconds(300)); return(true); }); Within(TimeSpan.FromSeconds(1), () => { fsm.Tell(new Cancel(), Self); expectMsgType <Cancel>(); expectMsg(new FSMBase.Transition <State>(fsm, State.TestStateTimeout, State.Initial), FSMSpecHelpers.TransitionStateExpector <State>()); return(true); }); //assert }
public override void Setup() { base.Setup(); //initializes the Finite State Machine, so it doesn't affect any of the time-sensitive tests below fsm.Tell(new FSMBase.SubscribeTransitionCallBack(Self)); expectMsg(new FSMBase.CurrentState <State>(fsm, State.Initial), FSMSpecHelpers.CurrentStateExpector <State>(), TimeSpan.FromSeconds(1)); }
public FSMTimingSpec() //: base("akka.test.test-actor.dispatcher.type=Dispatcher" + FullDebugConfig) //: base("akka.test.test-actor.dispatcher.type=Dispatcher" + FullDebugConfig) //: base(FullDebugConfig) { //initializes the Finite State Machine, so it doesn't affect any of the time-sensitive tests below fsm.Tell(new FSMBase.SubscribeTransitionCallBack(Self)); ExpectMsg(new FSMBase.CurrentState <State>(fsm, State.Initial), FSMSpecHelpers.CurrentStateExpector <State>(), TimeSpan.FromSeconds(1)); }
public void FSMTransitionNotifier_must_not_fail_when_listener_goes_away() { //arrange var forward = Sys.ActorOf(Props.Create(() => new Forwarder(TestActor))); var fsm = Sys.ActorOf(Props.Create(() => new MyFSM(TestActor))); //act Within(TimeSpan.FromSeconds(1), async() => { fsm.Tell(new FSMBase.SubscribeTransitionCallBack(forward)); ExpectMsg(new FSMBase.CurrentState <int>(fsm, 0), FSMSpecHelpers.CurrentStateExpector <int>()); await forward.GracefulStop(TimeSpan.FromSeconds(5)); fsm.Tell("tick"); ExpectNoMsg(TimeSpan.FromMilliseconds(300)); return(true); }); //assert }
public void FSMTransitionNotifier_must_notify_listeners() { //arrange var fsm = Sys.ActorOf(Props.Create(() => new MyFSM(TestActor))); //act Within(TimeSpan.FromSeconds(1), () => { fsm.Tell(new FSMBase.SubscribeTransitionCallBack(TestActor)); ExpectMsg(new FSMBase.CurrentState <int>(fsm, 0), FSMSpecHelpers.CurrentStateExpector <int>()); fsm.Tell("tick"); ExpectMsg(new FSMBase.Transition <int>(fsm, 0, 1), FSMSpecHelpers.TransitionStateExpector <int>()); fsm.Tell("tick"); ExpectMsg(new FSMBase.Transition <int>(fsm, 1, 0), FSMSpecHelpers.TransitionStateExpector <int>()); return(true); }); //assert }
public void FSM_must_not_get_confused_between_named_and_state_timers() { fsm.Tell(State.TestCancelStateTimerInNamedTimerMessage, Self); fsm.Tell(new Tick(), Self); expectMsg(new FSMBase.Transition <State>(fsm, State.Initial, State.TestCancelStateTimerInNamedTimerMessage), FSMSpecHelpers.TransitionStateExpector <State>()); expectMsgType <Tick>(TimeSpan.FromMilliseconds(500)); Task.Delay(TimeSpan.FromMilliseconds(200)); Resume(fsm); expectMsg(new FSMBase.Transition <State>(fsm, State.TestCancelStateTimerInNamedTimerMessage, State.TestCancelStateTimerInNamedTimerMessage2), FSMSpecHelpers.TransitionStateExpector <State>(), TimeSpan.FromMilliseconds(500)); fsm.Tell(new Cancel(), Self); Within(TimeSpan.FromMilliseconds(500), () => { expectMsgType <Cancel>(); expectMsg( new FSMBase.Transition <State>(fsm, State.TestCancelStateTimerInNamedTimerMessage2, State.Initial), FSMSpecHelpers.TransitionStateExpector <State>()); return(true); }); }
public void FSM_must_correctly_cancel_a_named_timer() { fsm.Tell(State.TestCancelTimer, Self); expectMsg(new FSMBase.Transition <State>(fsm, State.Initial, State.TestCancelTimer), FSMSpecHelpers.TransitionStateExpector <State>()); Within(TimeSpan.FromMilliseconds(500), () => { fsm.Tell(new Tick(), Self); expectMsgType <Tick>(); return(true); }); Within(TimeSpan.FromMilliseconds(300), TimeSpan.FromSeconds(1), () => { expectMsgType <Tock>(); return(true); }); fsm.Tell(new Cancel(), Self); expectMsg(new FSMBase.Transition <State>(fsm, State.TestCancelTimer, State.Initial), FSMSpecHelpers.TransitionStateExpector <State>(), TimeSpan.FromSeconds(1)); }
public void FSM_must_receive_single_shot_timer() { //arrange //act Within(TimeSpan.FromSeconds(2), () => { Within(TimeSpan.FromMilliseconds(450), TimeSpan.FromSeconds(1), () => { fsm.Tell(State.TestSingleTimer, Self); expectMsg(new FSMBase.Transition <State>(fsm, State.Initial, State.TestSingleTimer), FSMSpecHelpers.TransitionStateExpector <State>()); expectMsgType <Tick>(); expectMsg(new FSMBase.Transition <State>(fsm, State.TestSingleTimer, State.Initial), FSMSpecHelpers.TransitionStateExpector <State>()); return(true); }); expectNoMsg(TimeSpan.FromMilliseconds(500)); return(true); }); //assert }
public void FSM_must_receive_and_cancel_a_repeated_timer() { fsm.Tell(State.TestRepeatedTimer, Self); expectMsg(new FSMBase.Transition <State>(fsm, State.Initial, State.TestRepeatedTimer), FSMSpecHelpers.TransitionStateExpector <State>()); var seq = receiveWhile(TimeSpan.FromSeconds(2), o => { if (o is Tick) { return(o); } return(null); }); Assert.Equal(5, seq.Count); Within(TimeSpan.FromMilliseconds(500), () => { expectMsg(new FSMBase.Transition <State>(fsm, State.TestRepeatedTimer, State.Initial), FSMSpecHelpers.TransitionStateExpector <State>()); return(true); }); }
public void FSM_must_resubmit_single_shot_timer() { Within(TimeSpan.FromSeconds(2.5), () => { Within(TimeSpan.FromMilliseconds(450), TimeSpan.FromSeconds(1), () => { fsm.Tell(State.TestSingleTimerResubmit, Self); expectMsg(new FSMBase.Transition <State>(fsm, State.Initial, State.TestSingleTimerResubmit), FSMSpecHelpers.TransitionStateExpector <State>()); expectMsgType <Tick>(); return(true); }); Within(TimeSpan.FromSeconds(1), () => { expectMsgType <Tock>(); expectMsg(new FSMBase.Transition <State>(fsm, State.TestSingleTimerResubmit, State.Initial), FSMSpecHelpers.TransitionStateExpector <State>()); return(true); }); expectNoMsg(TimeSpan.FromMilliseconds(500)); return(true); }); }
public void FSM_must_cancel_a_StateTimeout() { //arrange //act Within(TimeSpan.FromSeconds(1), () => { fsm.Tell(State.TestStateTimeout, Self); fsm.Tell(new Cancel(), Self); ExpectMsg(new FSMBase.Transition <State>(fsm, State.Initial, State.TestStateTimeout), FSMSpecHelpers.TransitionStateExpector <State>()); ExpectMsg <Cancel>(); ExpectMsg(new FSMBase.Transition <State>(fsm, State.TestStateTimeout, State.Initial), FSMSpecHelpers.TransitionStateExpector <State>()); ExpectNoMsg(TimeSpan.FromMilliseconds(50)); return(true); }); //assert }