Merge pull request #21 from basho/slf/eunit-fixes1

Slf/eunit fixes1
This commit is contained in:
UENISHI Kota 2015-10-21 15:08:08 +09:00
commit 79e0ae9fe5
4 changed files with 39 additions and 18 deletions

View file

@ -45,12 +45,11 @@
%% List twiddling %% List twiddling
permutations/1, perms/1, permutations/1, perms/1,
combinations/1, ordered_combinations/1, combinations/1, ordered_combinations/1,
mk_order/2 mk_order/2,
%% Other
wait_for_death/2, wait_for_life/2
]). ]).
%% TODO: Leave this in place?
-compile(export_all).
-include("machi.hrl"). -include("machi.hrl").
-include("machi_projection.hrl"). -include("machi_projection.hrl").
-include_lib("kernel/include/file.hrl"). -include_lib("kernel/include/file.hrl").
@ -321,6 +320,17 @@ wait_for_death(Pid, Iters) when is_pid(Pid) ->
wait_for_death(Pid, Iters-1) wait_for_death(Pid, Iters-1)
end. end.
wait_for_life(Reg, 0) ->
exit({not_alive_yet, Reg});
wait_for_life(Reg, Iters) when is_atom(Reg) ->
case erlang:whereis(Reg) of
Pid when is_pid(Pid) ->
{ok, Pid};
_ ->
timer:sleep(1),
wait_for_life(Reg, Iters-1)
end.
%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
%% @doc Create a TCP connection to a remote Machi server. %% @doc Create a TCP connection to a remote Machi server.

View file

@ -284,7 +284,6 @@ smoke0_test() ->
timer:sleep(1), timer:sleep(1),
{ok, FLUaP} = ?FLU_PC:start_link(Pa), {ok, FLUaP} = ?FLU_PC:start_link(Pa),
{ok, M0} = ?MGR:start_link(a, Members_Dict, [{active_mode, false}]), {ok, M0} = ?MGR:start_link(a, Members_Dict, [{active_mode, false}]),
_SockA = machi_util:connect(Host, TcpPort),
try try
pong = ?MGR:ping(M0) pong = ?MGR:ping(M0)
after after
@ -294,7 +293,10 @@ smoke0_test() ->
ok = machi_partition_simulator:stop() ok = machi_partition_simulator:stop()
end. end.
smoke1_test() -> smoke1_test_() ->
{timeout, 1*60, fun() -> smoke1_test2() end}.
smoke1_test2() ->
machi_partition_simulator:start_link({1,2,3}, 100, 0), machi_partition_simulator:start_link({1,2,3}, 100, 0),
TcpPort = 62777, TcpPort = 62777,
FluInfo = [{a,TcpPort+0,"./data.a"}, {b,TcpPort+1,"./data.b"}, {c,TcpPort+2,"./data.c"}], FluInfo = [{a,TcpPort+0,"./data.a"}, {b,TcpPort+1,"./data.b"}, {c,TcpPort+2,"./data.c"}],
@ -309,12 +311,18 @@ smoke1_test() ->
try try
{ok, P1} = ?MGR:test_calc_projection(M0, false), {ok, P1} = ?MGR:test_calc_projection(M0, false),
% DERP! Check for race with manager's proxy vs. proj listener % DERP! Check for race with manager's proxy vs. proj listener
case ?MGR:test_read_latest_public_projection(M0, false) of ok = lists:foldl(
{error, partition} -> timer:sleep(500); fun(_, {_,{true,[{c,ok},{b,ok},{a,ok}]}}) ->
_ -> ok ok; % Short-circuit remaining attempts
end, (_, ok) ->
{remote_write_results,{true,[{c,ok},{b,ok},{a,ok}]}} = ok; % Skip remaining!
?MGR:test_write_public_projection(M0, P1), (_, _Else) ->
timer:sleep(10),
?MGR:test_write_public_projection(M0, P1)
end, not_ok, lists:seq(1, 1000)),
%% Writing the exact same projection multiple times returns ok:
%% no change!
{_,{true,[{c,ok},{b,ok},{a,ok}]}} = ?MGR:test_write_public_projection(M0, P1),
{unanimous, P1, Extra1} = ?MGR:test_read_latest_public_projection(M0, false), {unanimous, P1, Extra1} = ?MGR:test_read_latest_public_projection(M0, false),
ok ok
@ -337,8 +345,6 @@ nonunanimous_setup_and_fix_test() ->
%% {ok, Mb} = ?MGR:start_link(b, MembersDict, [{active_mode, false}]++XX), %% {ok, Mb} = ?MGR:start_link(b, MembersDict, [{active_mode, false}]++XX),
[{ok,_}=machi_flu_psup:start_flu_package(Name, Port, Dir, Opts) || [{ok,_}=machi_flu_psup:start_flu_package(Name, Port, Dir, Opts) ||
{Name,Port,Dir} <- FluInfo], {Name,Port,Dir} <- FluInfo],
FLUs = [machi_flu_psup:make_flu_regname(Name) ||
{Name,_Port,_Dir} <- FluInfo],
[Proxy_a, Proxy_b] = Proxies = [Proxy_a, Proxy_b] = Proxies =
[element(2,?FLU_PC:start_link(P)) || P <- P_s], [element(2,?FLU_PC:start_link(P)) || P <- P_s],
MembersDict = machi_projection:make_members_dict(P_s), MembersDict = machi_projection:make_members_dict(P_s),

View file

@ -32,6 +32,7 @@ smoke_test_() -> {timeout, 1*60, fun() -> smoke_test2() end}.
setup_smoke_test(Host, PortBase, Os, Witness_list) -> setup_smoke_test(Host, PortBase, Os, Witness_list) ->
os:cmd("rm -rf ./data.a ./data.b ./data.c"), os:cmd("rm -rf ./data.a ./data.b ./data.c"),
{ok, _} = machi_util:wait_for_life(machi_flu_sup, 100),
F = fun(X) -> case lists:member(X, Witness_list) of F = fun(X) -> case lists:member(X, Witness_list) of
true -> true ->
@ -185,9 +186,10 @@ smoke_test2() ->
ok ok
after after
exit(SupPid, normal),
machi_util:wait_for_death(SupPid, 100),
error_logger:tty(true), error_logger:tty(true),
catch application:stop(machi), catch application:stop(machi)
exit(SupPid, normal)
end. end.
witness_smoke_test_() -> {timeout, 1*60, fun() -> witness_smoke_test2() end}. witness_smoke_test_() -> {timeout, 1*60, fun() -> witness_smoke_test2() end}.

View file

@ -105,7 +105,10 @@ api_smoke_test() ->
(catch machi_flu1_test:stop_flu_package(RegName)) (catch machi_flu1_test:stop_flu_package(RegName))
end. end.
flu_restart_test() -> flu_restart_test_() ->
{timeout, 1*60, fun() -> flu_restart_test2() end}.
flu_restart_test2() ->
RegName = a, RegName = a,
Host = "localhost", Host = "localhost",
TcpPort = 57125, TcpPort = 57125,