简体   繁体   English

钢筋分布式测试

[英]Rebar distributed tests

I have some issue with distributed tests under rebar. 我在钢筋下进行分布式测试时遇到一些问题。 Rebar starts node with name nonode@nohost . 钢筋以名称nonode@nohost开头节点。 After it I call help function make_distrib which provide normal node name and starts distribution work. 之后,我调用帮助函数make_distrib ,该函数提供正常的节点名称并开始分发工作。
After starting the slave node I couldn't sent to it any lambda. 启动从属节点后,我无法向其发送任何lambda。 I had error: 我有错误:

=ERROR REPORT==== 27-Jul-2013::22:48:02 ===
    Error in process  on node 'test1@just' with exit value: {{badfun,#Fun<msg_proxy_tests.2.117197241>},[{error_handler,undefined_lambda,3,[{file,"error_handler.erl"},{line,64}]}]}

But! 但! If I run it test with simple way - all works good: 如果我以简单的方式进行测试-一切正常:

$erl
    1> c(msg_proxy_tests).
    {ok,msg_proxy_tests}
    2> eunit:test({module, msg_proxy_tests},[verbose]).
    ======================== EUnit ========================
    module 'msg_proxy_tests'msg_proxy_tests: distrib_mode_test_ (distribute mode test for nodes)...
    msg_proxy_tests.erl:14:<0.48.0>: nodes ( ) = [test1@just]
    msg_proxy_tests.erl:15:<9999.39.0>: node ( ) = test1@just
    msg_proxy_tests.erl:17:<0.48.0>: nodes ( ) = [test1@just]
    [0.238 s] ok

How can I fix this? 我怎样才能解决这个问题?


Module source: 模块来源:

\n\n    -module(msg_proxy_tests). -module(msg_proxy_tests)。\n\n    -include_lib("eunit/include/eunit.hrl"). -include_lib(“ eunit / include / eunit.hrl”)。\n\n    distrib_mode_test_()-> distrib_mode_test _()->\n    {"distribute mode test for nodes", timeout, 60, {“节点的分布式模式测试”,超时,60, \n        fun() -> fun()->\n            {ok, Host} = inet:gethostname(), {ok,主机} = inet:gethostname(),\n            make_distrib("tests@"++Host, shortnames), make_distrib(“ tests @” ++主机,简称),\n            slave:start(Host, test1), slave:start(主机,test1),\n            ?debugVal(nodes()), ?debugVal(nodes()),\n            spawn(list_to_atom("test1@"++Host), fun()-> ?debugVal(node()) end), spawn(list_to_atom(“ test1 @” ++ Host),fun()->?debugVal(node())结束),\n            timer:sleep(100), 计时器:睡眠(100), \n            ?debugVal(nodes()), ?debugVal(nodes()),\n            stop_distrib(), stop_distrib(),\n            ok \n        end}. 结束}。\n\n    -spec make_distrib( NodeName::string()|atom(), NodeType::shortnames | longnames) -> -spec make_distrib(NodeName :: string()| atom(),NodeType :: shortnames | longnames)->\n        {ok, ActualNodeName::atom} | {ok,ActualNodeName :: atom} | {error, Reason::term()}. {错误,原因:: term()}。\n    make_distrib(NodeName, NodeType) when is_list(NodeName) -> 当is_list(NodeName)-> make_distrib(NodeName,NodeType)\n        make_distrib(erlang:list_to_atom(NodeName), NodeType); make_distrib(erlang:list_to_atom(NodeName),NodeType);\n    make_distrib(NodeName, NodeType) -> make_distrib(NodeName,NodeType)->\n        case node() of 的case node()\n            'nonode@nohost' -> 'nonode @ nohost'-> \n                [] = os:cmd("epmd -daemon"), [] = os:cmd(“ epmd -daemon”),\n                case net_kernel:start([NodeName, NodeType]) of net_kernel:start([NodeName,NodeType])的情况 \n                    {ok, _Pid} -> node() {ok,_Pid}-> node() \n                end; 结束;\n            CurrNode -> CurrNode CurrNode-> CurrNode\n        end. 结束。\n\n    stop_distrib()-> stop_distrib()->\n        net_kernel:stop(). net_kernel:stop()。\n\n

That is because of module hash on both nodes is different. 这是因为两个节点上的模块哈希不同。 That happens because eunit compiles code before it run and module contains -ifdef(TEST) macroses, which will definitely change it's hash. 发生这种情况是因为eunit在运行之前会编译代码,并且模块包含-ifdef(TEST)宏,这肯定会更改其哈希值。

Thats why anonymous function #Fun<msg_proxy_tests.2.117197241 could not be called and error occurred. 这就是为什么无法调用匿名函数#Fun<msg_proxy_tests.2.117197241并发生错误的原因。 (look at function name and you will notice funny numbers, this is module hash, it will be different on both nodes). (查看函数名称,您会注意到有趣的数字,这是模块哈希,在两个节点上都不同)。

If you want to avoid this, you should call funs by it fully qualified name: module:fun_name/arity . 如果要避免这种情况,则应使用完全限定的名称来调用module:fun_name/aritymodule:fun_name/arity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM