Created
December 18, 2010 16:25
-
-
Save kuenishi/746630 to your computer and use it in GitHub Desktop.
distributed eunit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(et). | |
% $ erl -make ; erl -sname eu -noshell -eval 'eunit:test(".", []).' -s init stop | |
-include_lib("eunit/include/eunit.hrl"). | |
pattern1_test_no()-> | |
{inparallel, | |
[ | |
{setup, local, | |
fun() -> {ok,P}=slave:start(net_adm:localhost(), child, "-sname left") end, | |
fun({ok,P}) -> slave:stop(P) end, | |
[ | |
fun()-> ?debugHere end, | |
?_assert(remote_apply('left@localhost', fun() -> true end)), | |
[{node, 'child@localhost', | |
[ fun()-> ?debugVal({node(),nodes()}) end, | |
fun()-> ?assert(false) end ]}] | |
]}, | |
fun()-> ?debugHere end, | |
fun()-> ?debugHere end, | |
fun()-> ?debugHere end | |
]}. | |
% http://erlang.2086793.n4.nabble.com/Eunit-multinode-test-help-td2102265.html | |
pattern2_test_no()-> | |
RN = 'left@localhost', | |
{node, RN, {setup, {spawn,RN}, | |
fun()-> ?debugHere end, | |
fun(_)-> ?debugHere end, | |
[?_assert(remote_apply(RN, fun() -> true end)) ] | |
}}. | |
remote_apply(Node, Fun) -> remote_apply(Node, Fun, []). | |
remote_apply(Node, Fun, Args) -> | |
rpc:call(Node, erlang, apply, [ Fun, Args ], 5000). | |
%%results in: | |
%% connect to address ::1: Connection refused | |
%% Trying fe80::1%lo0... | |
%% connect to address fe80::1%lo0: Connection refused | |
%% Trying 127.0.0.1... | |
%% localhost: Connection refused | |
rcall_slave(Name, Fun, Argv) when is_atom(Name) -> | |
Host = get_slave_name(Name), | |
rpc:call(Host,erlang,apply,[Fun,Argv],10000). | |
-define( _rassert(Name, Expr), ?_assert(rcall_slave(Name, fun()->Expr end, []))). | |
pattern3_test_()-> | |
Setup=fun() -> {ok,P}=slave:start(net_adm:localhost(), child, " ") end, | |
Clean=fun({ok,P}) -> slave:stop(P) end, | |
{setup, local, | |
Setup, Clean, | |
[ | |
fun()-> ?debugVal(rpc:call('child@shuna',erlang,apply,[fun()-> erlang:display(hoge) end, []])) end, | |
?_assert( remote_apply('child@shuna', fun()-> ?debugHere, true end) ), | |
call_slave(child,fun()-> ?debugHere, true end, []), % use this | |
?_rassert(child, false), % use this | |
fun()-> ?debugHere end | |
]}. | |
call_slave(Name, Fun, Argv) when is_atom(Name) -> | |
Host = get_slave_name(Name), | |
fun()-> rpc:call(Host,erlang,apply,[Fun,Argv],10000) end. | |
get_slave_name(Name)-> | |
Host0 = strip_host_name(net_adm:localhost()), | |
list_to_atom(lists:concat([Name,"@",Host0])). | |
strip_host_name([]) -> []; | |
strip_host_name([$.|_]) -> []; | |
strip_host_name([H|T]) -> [H|strip_host_name(T)]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment