针对超时的eunit测试

时间:2012-03-22 10:37:45

标签: unit-testing erlang otp gen-fsm eunit

如何通过eunit测试gen_fsm确实超时?

{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?

1 个答案:

答案 0 :(得分:1)

我相信这是一个解决方案:

{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.