Make test start up more reliable

This commit is contained in:
Mark Allen 2015-10-08 15:49:22 -05:00
parent d9ede473dd
commit 5926cef44a
3 changed files with 87 additions and 38 deletions

View file

@ -39,10 +39,10 @@ clean_up_data_dir(DataDir) ->
_ = file:del_dir(DataDir),
ok.
setup_test_flu(RegName, TcpPort, DataDir) ->
setup_test_flu(RegName, TcpPort, DataDir, []).
xxx_setup_test_flu(RegName, TcpPort, DataDir) ->
xxx_setup_test_flu(RegName, TcpPort, DataDir, []).
setup_test_flu(RegName, TcpPort, DataDir, Props) ->
xxx_setup_test_flu(RegName, TcpPort, DataDir, Props) ->
case proplists:get_value(save_data_dir, Props) of
true ->
ok;
@ -57,6 +57,38 @@ setup_test_flu(RegName, TcpPort, DataDir, Props) ->
timer:sleep(10),
FLU1.
start_flu_package(RegName, TcpPort, DataDir) ->
start_flu_package(RegName, TcpPort, DataDir, []).
start_flu_package(RegName, TcpPort, DataDir, Props) ->
case proplists:get_value(save_data_dir, Props) of
true ->
ok;
_ ->
clean_up_data_dir(DataDir)
end,
maybe_start_sup(),
machi_flu_psup:start_flu_package(RegName, TcpPort, DataDir, Props).
stop_flu_package(FluName) ->
machi_flu_psup:stop_flu_package(FluName),
Pid = whereis(machi_sup),
exit(Pid, normal),
%% evil but we have to let stuff shutdown
timer:sleep(10).
maybe_start_sup() ->
case whereis(machi_sup) of
undefined ->
machi_sup:start_link(),
%% evil but we have to let stuff start up
timer:sleep(10),
maybe_start_sup();
Pid -> Pid
end.
-ifndef(PULSE).
flu_smoke_test() ->
@ -67,7 +99,7 @@ flu_smoke_test() ->
BadPrefix = BadFile = "no/good",
W_props = [{initial_wedged, false}],
FLU1 = setup_test_flu(smoke_flu, TcpPort, DataDir, W_props),
start_flu_package(smoke_flu, TcpPort, DataDir, W_props),
try
Msg = "Hello, world!",
Msg = ?FLU_C:echo(Host, TcpPort, Msg),
@ -158,7 +190,7 @@ flu_smoke_test() ->
ok = ?FLU_C:quit(?FLU_C:connect(#p_srvr{address=Host,
port=TcpPort}))
after
ok = ?FLU:stop(FLU1)
stop_flu_package(smoke_flu)
end.
flu_projection_smoke_test() ->
@ -166,14 +198,14 @@ flu_projection_smoke_test() ->
TcpPort = 32959,
DataDir = "./data",
FLU1 = setup_test_flu(projection_test_flu, TcpPort, DataDir),
start_flu_package(projection_test_flu, TcpPort, DataDir),
try
[ok = flu_projection_common(Host, TcpPort, T) ||
T <- [public, private] ]
%% , {ok, {false, EpochID1}} = ?FLU_C:wedge_status(Host, TcpPort),
%% io:format(user, "EpochID1 ~p\n", [EpochID1])
after
ok = ?FLU:stop(FLU1)
stop_flu_package(projection_test_flu)
end.
flu_projection_common(Host, TcpPort, T) ->
@ -204,7 +236,7 @@ bad_checksum_test() ->
DataDir = "./data",
Opts = [{initial_wedged, false}],
FLU1 = setup_test_flu(projection_test_flu, TcpPort, DataDir, Opts),
start_flu_package(projection_test_flu, TcpPort, DataDir, Opts),
try
Prefix = <<"some prefix">>,
Chunk1 = <<"yo yo yo">>,
@ -214,7 +246,7 @@ bad_checksum_test() ->
Prefix, Chunk1_badcs),
ok
after
ok = ?FLU:stop(FLU1)
stop_flu_package(projection_test_flu)
end.
witness_test() ->
@ -223,7 +255,7 @@ witness_test() ->
DataDir = "./data",
Opts = [{initial_wedged, false}, {witness_mode, true}],
FLU1 = setup_test_flu(projection_test_flu, TcpPort, DataDir, Opts),
start_flu_package(projection_test_flu, TcpPort, DataDir, Opts),
try
Prefix = <<"some prefix">>,
Chunk1 = <<"yo yo yo">>,
@ -255,7 +287,7 @@ witness_test() ->
ok
after
ok = ?FLU:stop(FLU1)
stop_flu_package(projection_test_flu)
end.
%% The purpose of timing_pb_encoding_test_ and timing_bif_encoding_test_ is

View file

@ -29,12 +29,11 @@
-include("machi_projection.hrl").
smoke_test() ->
{ok, SupPid} = machi_flu_sup:start_link(),
PortBase = 64820,
Dir = "./data.a",
Os = [{ignore_stability_time, true}, {active_mode, false}],
os:cmd("rm -rf " ++ Dir),
{ok,Yo}=machi_flu_psup:start_flu_package(a, PortBase, "./data.a", Os),
machi_flu1_test:start_flu_package(a, PortBase, "./data.a", Os),
try
P1 = machi_projection:new(1, a, [], [], [], [], []),
@ -59,9 +58,7 @@ smoke_test() ->
ok
after
machi_flu_psup:stop_flu_package(a),
exit(SupPid, normal),
timer:sleep(10)
machi_flu1_test:stop_flu_package(a)
end.
-endif. % !PULSE

View file

@ -37,9 +37,8 @@ api_smoke_test() ->
DataDir = "./data.api_smoke_flu",
W_props = [{initial_wedged, false}],
Prefix = <<"prefix">>,
FLU1 = machi_flu1_test:setup_test_flu(RegName, TcpPort, DataDir,
W_props),
erase(flu_pid),
machi_flu1_test:start_flu_package(RegName, TcpPort, DataDir, W_props),
try
I = #p_srvr{name=RegName, address=Host, port=TcpPort},
@ -50,14 +49,13 @@ api_smoke_test() ->
FakeEpoch, Prefix, <<"data">>,
infinity) || _ <- lists:seq(1,5)],
%% Stop the FLU, what happens?
machi_flu1:stop(FLU1),
machi_flu1_test:stop_flu_package(RegName),
[{error,partition} = ?MUT:append_chunk(Prox1,
FakeEpoch, Prefix, <<"data-stopped1">>,
infinity) || _ <- lists:seq(1,3)],
%% Start the FLU again, we should be able to do stuff immediately
FLU1b = machi_flu1_test:setup_test_flu(RegName, TcpPort, DataDir,
machi_flu1_test:start_flu_package(RegName, TcpPort, DataDir,
[save_data_dir|W_props]),
put(flu_pid, FLU1b),
MyChunk = <<"my chunk data">>,
{ok, {MyOff,MySize,MyFile}} =
?MUT:append_chunk(Prox1, FakeEpoch, Prefix, MyChunk,
@ -85,23 +83,50 @@ api_smoke_test() ->
{error, no_such_file} = ?MUT:checksum_list(Prox1, FakeEpoch, BadFile),
{ok, [_|_]} = ?MUT:list_files(Prox1, FakeEpoch),
{ok, {false, _}} = ?MUT:wedge_status(Prox1),
{ok, FakeEpoch} = ?MUT:get_latest_epochid(Prox1, public),
{error, not_written} = ?MUT:read_latest_projection(Prox1, public),
%% Per Scott, comment this out until he can take a look
%%
%% machi_proxy_flu1_client_test: api_smoke_test...*failed*
%% in function machi_proxy_flu1_client_test:api_smoke_test/0 (test/machi_proxy_flu1_client_test.erl, line 88)
%% **error:{badmatch,{ok,{0,<<55,96,141,95,149,143,223,4,14,235,88,15,47,...>>}}}
%%
%% {ok, FakeEpoch} = ?MUT:get_latest_epochid(Prox1, public),
%% in function machi_proxy_flu1_client_test:api_smoke_test/0 (test/machi_proxy_flu1_client_test.erl, line 89)
%% **error:{badmatch,{ok,{projection_v1,0,
%% <<55,96,141,95,149,143,223,4,14,235,88,15,...>>,
%% api_smoke_flu,[],[],
%% {1444,330495,507785},
%% ap_mode,[],[],[],[],[],[]}}}
%% {error, not_written} = ?MUT:read_latest_projection(Prox1, public),
{error, not_written} = ?MUT:read_projection(Prox1, public, 44),
P_a = #p_srvr{name=a, address="localhost", port=6622},
P1 = machi_projection:new(1, a, [P_a], [], [a], [], []),
ok = ?MUT:write_projection(Prox1, public, P1),
{ok, P1} = ?MUT:read_projection(Prox1, public, 1),
{ok, [P1]} = ?MUT:get_all_projections(Prox1, public),
{ok, [1]} = ?MUT:list_all_projections(Prox1, public),
%%
%% in function machi_proxy_flu1_client_test:api_smoke_test/0 (test/machi_proxy_flu1_client_test.erl, line 107)
%% **error:{badmatch,{ok,[{projection_v1,0,
%% <<55,96,141,95,149,143,223,4,14,235,88,...>>,
%% api_smoke_flu,[],[],
%% {1444,330601,749713},
%% ap_mode,[],[],[],[],[],[]},
%% {projection_v1,1,
%% <<156,33,125,69,126,173,34,245,78,95,...>>,
%% a,
%% [a],
%% [],
%% {1444,330601,820732},
%% ap_mode,
%% [a],
%% [],[],[],[],...}]}}
%% {ok, [P1]} = ?MUT:get_all_projections(Prox1, public),
%% {ok, [1]} = ?MUT:list_all_projections(Prox1, public),
ok
after
_ = (catch ?MUT:quit(Prox1))
end
after
(catch machi_flu1:stop(FLU1)),
(catch machi_flu1:stop(get(flu_pid)))
(catch machi_flu1_test:stop_flu_package(RegName))
end.
flu_restart_test() ->
@ -110,11 +135,7 @@ flu_restart_test() ->
TcpPort = 57125,
DataDir = "./data.api_smoke_flu2",
W_props = [{initial_wedged, false}],
erase(flu_pid),
put(flu_pid, []),
FLU1 = machi_flu1_test:setup_test_flu(RegName, TcpPort, DataDir,
W_props),
put(flu_pid, [FLU1|get(flu_pid)]),
machi_flu1_test:start_flu_package(RegName, TcpPort, DataDir, W_props),
try
I = #p_srvr{name=RegName, address=Host, port=TcpPort},
@ -137,7 +158,7 @@ flu_restart_test() ->
{ok, EpochID} = ?MUT:get_epoch_id(Prox1),
{ok, EpochID} = ?MUT:get_latest_epochid(Prox1, public),
{ok, EpochID} = ?MUT:get_latest_epochid(Prox1, private),
ok = machi_flu1:stop(FLU1), timer:sleep(50),
ok = machi_flu1_test:stop_flu_package(RegName), timer:sleep(50),
%% Now that the last proxy op was successful and only
%% after did we stop the FLU, let's check that both the
@ -295,14 +316,13 @@ flu_restart_test() ->
],
[begin
FLU2 = machi_flu1_test:setup_test_flu(
machi_flu1_test:start_flu_package(
RegName, TcpPort, DataDir,
[save_data_dir|W_props]),
put(flu_pid, [FLU2|get(flu_pid)]),
_ = Fun(line),
ok = Fun(run),
ok = Fun(run),
ok = machi_flu1:stop(FLU2),
ok = machi_flu1_test:stop_flu_package(RegName),
{error, partition} = Fun(stop),
{error, partition} = Fun(stop),
ok
@ -312,7 +332,7 @@ flu_restart_test() ->
_ = (catch ?MUT:quit(Prox1))
end
after
[catch machi_flu1:stop(Pid) || Pid <- get(flu_pid)]
(catch machi_flu1_test:stop_flu_package(RegName))
end.
-endif. % !PULSE