【问题标题】:eunit test for timeouteunit 测试超时
【发布时间】:2012-04-06 21:58:13
【问题描述】:

如何测试 gen_fsm 是否确实与 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?

【问题讨论】:

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


    【解决方案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.
    

    【讨论】:

    • 我得到:xxx_tests: xxx_timeout_test...*超时* undefined ============================ =========================== 失败:0。跳过:0。通过:0。取消了一项或多项测试。错误
    • 已解决,消息不是关于进程停止,而是关于测试本身。用 {timout, 30, fun()-> test code} 括起来。现在它可以工作了。
    猜你喜欢
    • 2016-07-25
    • 2013-08-04
    • 2012-02-28
    • 2011-12-27
    • 2012-05-24
    • 1970-01-01
    • 2016-06-03
    • 2015-06-13
    • 2014-04-11
    相关资源
    最近更新 更多