Search code examples
unit-testingerlangerlang-otpgen-fsmeunit

eunit test for timeout


How can I test that a gen_fsm does indeed timeout with eunit?

{ok, GH} = gen_fsm:start_link(myFSM, [], []),
//after 15 sec it should timeout if no messages received. 
//What must I write here to test it?

Solution

  • I believe this is one solution:

    {ok, GH} = gen_fsm:start_link(myFSM, [], []),
    Ref = erlang:monitor(process,GH),
    receive
        {'DOWN', Ref, process, GH,  normal} ->
            test_passed
    after 
        15000 ->
            ?assert("FSM did not die.") % will always fail
    end.