1

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?
Daniel
  • 20,420
  • 10
  • 92
  • 149

1 Answers1

1

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.
Isac
  • 2,058
  • 16
  • 23
  • I get: xxx_tests: xxx_timeout_test...*timed out* undefined ======================================================= Failed: 0. Skipped: 0. Passed: 0. One or more tests were cancelled. error – Daniel Mar 22 '12 at 20:03
  • solved, the msg wasn't about the process going down, but about the test itself. Enclosed it with {timout, 30, fun()-> *test code*}. And now it works. – Daniel Mar 23 '12 at 09:23