More cleaner clean up

This commit is contained in:
Shunichi Shinohara 2015-12-08 15:38:27 +09:00
parent aa0a0413d1
commit ade4430d30
3 changed files with 19 additions and 10 deletions

View file

@ -82,7 +82,12 @@ start_link([{FluName, TcpPort, DataDir}|Rest])
proc_lib:start_link(?MODULE, main2, [FluName, TcpPort, DataDir, Rest],
?INIT_TIMEOUT).
stop(Pid) ->
stop(RegName) when is_atom(RegName) ->
case whereis(RegName) of
undefined -> ok;
Pid -> stop(Pid)
end;
stop(Pid) when is_pid(Pid) ->
case erlang:is_process_alive(Pid) of
true ->
Pid ! killme,

View file

@ -53,7 +53,7 @@ api_smoke_test() ->
infinity) || _ <- lists:seq(1,3)],
%% Start the FLU again, we should be able to do stuff immediately
machi_test_util:start_flu_package(RegName, TcpPort, DataDir,
[save_data_dir|W_props]),
[no_cleanup|W_props]),
MyChunk = <<"my chunk data">>,
{ok, {MyOff,MySize,MyFile}} =
?MUT:append_chunk(Prox1, FakeEpoch, Prefix, MyChunk,
@ -148,7 +148,7 @@ flu_restart_test2() ->
ExpectedOps =
[
fun(run) -> {ok, EpochID} = ?MUT:get_epoch_id(Prox1),
fun(run) -> ?assertEqual({ok, EpochID}, ?MUT:get_epoch_id(Prox1)),
ok;
(line) -> io:format("line ~p, ", [?LINE]);
(stop) -> ?MUT:get_epoch_id(Prox1) end,
@ -292,7 +292,7 @@ flu_restart_test2() ->
[begin
machi_test_util:start_flu_package(
RegName, TcpPort, DataDir,
[save_data_dir|W_props]),
[no_cleanup|W_props]),
_ = Fun(line),
ok = Fun(run),
ok = Fun(run),

View file

@ -54,7 +54,7 @@ start_flu_packages(FluCount, BaseTcpPort, DirPrefix, Props) ->
start_flu_packages(FluInfo) ->
_ = stop_machi_sup(),
clean_up_data_dirs(FluInfo),
clean_up(FluInfo),
{ok, _SupPid} = machi_sup:start_link(),
[{ok, _} = machi_flu_psup:start_flu_package(Name, Port, Dir, Props) ||
{#p_srvr{name=Name, port=Port, props=Props}, Dir, _} <- FluInfo],
@ -86,11 +86,15 @@ stop_machi_sup() ->
machi_util:wait_for_death(Pid, 30)
end.
clean_up_data_dirs(FluInfo) ->
_ = [case proplists:get_value(save_data_dir, Propx) of
true -> ok;
_ -> clean_up_dir(Dir)
end || {#p_srvr{props=Propx}, Dir, _} <- FluInfo],
clean_up(FluInfo) ->
_ = [begin
case proplists:get_value(no_cleanup, Props) of
true -> ok;
_ ->
_ = machi_flu1:stop(FLUName),
clean_up_dir(Dir)
end
end || {#p_srvr{name=FLUName, props=Props}, Dir, _} <- FluInfo],
ok.
clean_up_dir(Dir) ->