Slf/eunit fixes1 #21

Merged
slfritchie merged 4 commits from slf/eunit-fixes1 into master 2015-10-21 06:08:08 +00:00
4 changed files with 39 additions and 18 deletions

View file

@ -45,12 +45,11 @@
%% List twiddling
permutations/1, perms/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_projection.hrl").
-include_lib("kernel/include/file.hrl").
@ -316,11 +315,22 @@ wait_for_death(Pid, Iters) when is_pid(Pid) ->
case erlang:is_process_alive(Pid) of
false ->
ok;
true ->
true ->
timer:sleep(1),
wait_for_death(Pid, Iters-1)
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.

View file

@ -284,7 +284,6 @@ smoke0_test() ->
timer:sleep(1),
{ok, FLUaP} = ?FLU_PC:start_link(Pa),
{ok, M0} = ?MGR:start_link(a, Members_Dict, [{active_mode, false}]),
_SockA = machi_util:connect(Host, TcpPort),
try
pong = ?MGR:ping(M0)
after
@ -294,7 +293,10 @@ smoke0_test() ->
ok = machi_partition_simulator:stop()
end.
smoke1_test() ->
smoke1_test_() ->
{timeout, 1*60, fun() -> smoke1_test2() end}.
smoke1_test2() ->
machi_partition_simulator:start_link({1,2,3}, 100, 0),
TcpPort = 62777,
FluInfo = [{a,TcpPort+0,"./data.a"}, {b,TcpPort+1,"./data.b"}, {c,TcpPort+2,"./data.c"}],
@ -309,12 +311,18 @@ smoke1_test() ->
try
{ok, P1} = ?MGR:test_calc_projection(M0, false),
% DERP! Check for race with manager's proxy vs. proj listener
case ?MGR:test_read_latest_public_projection(M0, false) of
{error, partition} -> timer:sleep(500);
_ -> ok
end,
{remote_write_results,{true,[{c,ok},{b,ok},{a,ok}]}} =
?MGR:test_write_public_projection(M0, P1),
ok = lists:foldl(
fun(_, {_,{true,[{c,ok},{b,ok},{a,ok}]}}) ->
ok; % Short-circuit remaining attempts
(_, ok) ->
ok; % Skip remaining!
(_, _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),
ok
@ -337,8 +345,6 @@ nonunanimous_setup_and_fix_test() ->
%% {ok, Mb} = ?MGR:start_link(b, MembersDict, [{active_mode, false}]++XX),
[{ok,_}=machi_flu_psup:start_flu_package(Name, Port, Dir, Opts) ||
{Name,Port,Dir} <- FluInfo],
FLUs = [machi_flu_psup:make_flu_regname(Name) ||
{Name,_Port,_Dir} <- FluInfo],
[Proxy_a, Proxy_b] = Proxies =
[element(2,?FLU_PC:start_link(P)) || P <- 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) ->
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
true ->
@ -185,9 +186,10 @@ smoke_test2() ->
ok
after
exit(SupPid, normal),
machi_util:wait_for_death(SupPid, 100),
error_logger:tty(true),
catch application:stop(machi),
exit(SupPid, normal)
catch application:stop(machi)
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))
end.
flu_restart_test() ->
flu_restart_test_() ->
{timeout, 1*60, fun() -> flu_restart_test2() end}.
flu_restart_test2() ->
RegName = a,
Host = "localhost",
TcpPort = 57125,