Clean up test errors

This commit is contained in:
Scott Lystig Fritchie 2015-12-10 15:57:35 +09:00
parent cb706f0d23
commit 9472bad37b
6 changed files with 60 additions and 34 deletions

View file

@ -1,6 +1,6 @@
%% ------------------------------------------------------------------- %% -------------------------------------------------------------------
%% %%
%% Copyright (c) 2007-2014 Basho Technologies, Inc. All Rights Reserved. %% Copyright (c) 2007-2015 Basho Technologies, Inc. All Rights Reserved.
%% %%
%% This file is provided to you under the Apache License, %% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file %% Version 2.0 (the "License"); you may not use this file
@ -78,15 +78,15 @@
-define(MAX_CHAIN_LENGTH, 64). -define(MAX_CHAIN_LENGTH, 64).
-record(chain_def_v1, { -record(chain_def_v1, {
name :: atom(), name :: atom(), % chain name
mode :: pv1_consistency_mode(), mode :: pv1_consistency_mode(),
full :: [p_srvr()], full = [] :: [p_srvr()],
witnesses :: [p_srvr()], witnesses = [] :: [p_srvr()],
old_all :: [pv1_server()], % guard against some races old_all = [] :: [pv1_server()], % guard against some races
old_witnesses :: [pv1_server()], % guard against some races old_witnesses=[] :: [pv1_server()], % guard against some races
local_run :: [pv1_server()], % must be tailored to each machine! local_run = [] :: [pv1_server()], % must be tailored to each machine!
local_stop :: [pv1_server()], % must be tailored to each machine! local_stop = [] :: [pv1_server()], % must be tailored to each machine!
props = [] :: list() % proplist for other related info props = [] :: list() % proplist for other related info
}). }).
-endif. % !MACHI_PROJECTION_HRL -endif. % !MACHI_PROJECTION_HRL

View file

@ -96,7 +96,7 @@ make_package_spec(FluName, TcpPort, DataDir, Props) ->
permanent, ?SHUTDOWN, supervisor, []}. permanent, ?SHUTDOWN, supervisor, []}.
start_flu_package(#p_srvr{name=FluName, port=TcpPort, props=Props}) -> start_flu_package(#p_srvr{name=FluName, port=TcpPort, props=Props}) ->
DataDir = get_data_dir(Props), DataDir = get_data_dir(FluName, Props),
start_flu_package(FluName, TcpPort, DataDir, Props). start_flu_package(FluName, TcpPort, DataDir, Props).
start_flu_package(FluName, TcpPort, DataDir, Props) -> start_flu_package(FluName, TcpPort, DataDir, Props) ->
@ -177,11 +177,11 @@ get_env(Setting, Default) ->
{ok, V} -> V {ok, V} -> V
end. end.
get_data_dir(Props) -> get_data_dir(FluName, Props) ->
case proplists:get_value(data_dir, Props) of case proplists:get_value(data_dir, Props) of
Path when is_list(Path) -> Path when is_list(Path) ->
Path; Path;
undefined -> undefined ->
{ok, Dir} = application:get_env(machi, flu_data_dir), {ok, Dir} = application:get_env(machi, flu_data_dir),
Dir Dir ++ "/" ++ atom_to_list(FluName)
end. end.

View file

@ -205,6 +205,9 @@
%% API %% API
-export([start_link/0, -export([start_link/0,
process_pending/0]). process_pending/0]).
-ifdef(TEST).
-compile(export_all).
-endif. % TEST
%% gen_server callbacks %% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@ -548,8 +551,8 @@ process_pending_chain2(File, CD, RemovedFLUs, ChainConfigAction, S) ->
[] -> [] ->
ok; ok;
[_|_] -> [_|_] ->
%% Sleep for a little bit to allow HC to settle. %% %% Sleep for a little bit to allow HC to settle.
timer:sleep(3000), %% timer:sleep(1000),
[begin [begin
%% We may be retrying this, so be liberal with any pattern %% We may be retrying this, so be liberal with any pattern
%% matching on return values. %% matching on return values.

View file

@ -955,7 +955,7 @@ conv_from_status({error, partial_read}) ->
conv_from_status({error, bad_epoch}) -> conv_from_status({error, bad_epoch}) ->
'BAD_EPOCH'; 'BAD_EPOCH';
conv_from_status(_OOPS) -> conv_from_status(_OOPS) ->
io:format(user, "HEY, ~s:~w got ~w\n", [?MODULE, ?LINE, _OOPS]), io:format(user, "HEY, ~s:~w got ~p\n", [?MODULE, ?LINE, _OOPS]),
'BAD_JOSS'. 'BAD_JOSS'.
conv_to_boolean(undefined) -> conv_to_boolean(undefined) ->

View file

@ -273,6 +273,17 @@ make_prop_ets() ->
-endif. % EQC -endif. % EQC
make_advance_fun(FitList, FLUList, MgrList, Num) ->
fun() ->
[begin
[catch machi_fitness:trigger_early_adjustment(Fit, Tgt) ||
Fit <- FitList,
Tgt <- FLUList ],
[catch ?MGR:trigger_react_to_env(Mgr) || Mgr <- MgrList],
ok
end || _ <- lists:seq(1, Num)]
end.
smoke0_test() -> smoke0_test() ->
{ok, _} = machi_partition_simulator:start_link({1,2,3}, 50, 50), {ok, _} = machi_partition_simulator:start_link({1,2,3}, 50, 50),
Host = "localhost", Host = "localhost",
@ -348,6 +359,7 @@ nonunanimous_setup_and_fix_test2() ->
[machi_flu1_test:clean_up_data_dir(Dir) || {_,_,Dir} <- FluInfo], [machi_flu1_test:clean_up_data_dir(Dir) || {_,_,Dir} <- FluInfo],
{ok, SupPid} = machi_flu_sup:start_link(), {ok, SupPid} = machi_flu_sup:start_link(),
Opts = [{active_mode, false}, {initial_wedged, true}], Opts = [{active_mode, false}, {initial_wedged, true}],
ChainName = my_little_chain,
[{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],
Proxies = [Proxy_a, Proxy_b, Proxy_c] = Proxies = [Proxy_a, Proxy_b, Proxy_c] =
@ -356,19 +368,14 @@ nonunanimous_setup_and_fix_test2() ->
MembersDict = machi_projection:make_members_dict(lists:sublist(P_s, 2)), MembersDict = machi_projection:make_members_dict(lists:sublist(P_s, 2)),
Mgrs = [Ma,Mb,Mc] = [a_chmgr, b_chmgr, c_chmgr], Mgrs = [Ma,Mb,Mc] = [a_chmgr, b_chmgr, c_chmgr],
MgrProxies = [{Ma, Proxy_a}, {Mb, Proxy_b}, {Mc, Proxy_c}], MgrProxies = [{Ma, Proxy_a}, {Mb, Proxy_b}, {Mc, Proxy_c}],
Advance = fun() -> Advance = make_advance_fun([a_fitness,b_fitness,c_fitness],
[begin [a,b,c],
[catch machi_fitness:trigger_early_adjustment(Fit, Tgt) || [Mgr || {Mgr,_Proxy} <- MgrProxies],
Fit <- [a_fitness,b_fitness,c_fitness], 3),
Tgt <- [a,b,c] ], ok = machi_chain_manager1:set_chain_members(Ma, ChainName, 0, ap_mode,
[catch ?MGR:trigger_react_to_env(Mgr) || MembersDict, []),
{Mgr,_Proxy} <- MgrProxies], ok = machi_chain_manager1:set_chain_members(Mb, ChainName, 0, ap_mode,
ok MembersDict, []),
end || _ <- lists:seq(1, 3)]
end,
ok = machi_chain_manager1:set_chain_members(Ma, MembersDict),
ok = machi_chain_manager1:set_chain_members(Mb, MembersDict),
try try
{ok, P1} = ?MGR:test_calc_projection(Ma, false), {ok, P1} = ?MGR:test_calc_projection(Ma, false),
@ -410,7 +417,7 @@ nonunanimous_setup_and_fix_test2() ->
MembersDict3 = machi_projection:make_members_dict(P_s), MembersDict3 = machi_projection:make_members_dict(P_s),
ok = machi_chain_manager1:set_chain_members( ok = machi_chain_manager1:set_chain_members(
Ma, ch_not_def_yet, EpochNum_a, ap_mode, MembersDict3, []), Ma, ChainName, EpochNum_a, ap_mode, MembersDict3, []),
Advance(), Advance(),
{_, _, TheEpoch_3} = ?MGR:trigger_react_to_env(Ma), {_, _, TheEpoch_3} = ?MGR:trigger_react_to_env(Ma),
@ -424,7 +431,7 @@ nonunanimous_setup_and_fix_test2() ->
MembersDict4 = machi_projection:make_members_dict(tl(P_s)), MembersDict4 = machi_projection:make_members_dict(tl(P_s)),
ok = machi_chain_manager1:set_chain_members( ok = machi_chain_manager1:set_chain_members(
Mb, ch_not_def_yet, TheEpoch_3, ap_mode, MembersDict4, []), Mb, ChainName, TheEpoch_3, ap_mode, MembersDict4, []),
Advance(), Advance(),
{ok, {true, _}} = ?FLU_PC:wedge_status(Proxy_a), {ok, {true, _}} = ?FLU_PC:wedge_status(Proxy_a),
@ -438,7 +445,7 @@ nonunanimous_setup_and_fix_test2() ->
MembersDict5 = machi_projection:make_members_dict(P_s), MembersDict5 = machi_projection:make_members_dict(P_s),
ok = machi_chain_manager1:set_chain_members( ok = machi_chain_manager1:set_chain_members(
Mb, ch_not_def_yet, TheEpoch_4, ap_mode, MembersDict5, []), Mb, ChainName, TheEpoch_4, ap_mode, MembersDict5, []),
Advance(), Advance(),
{_, _, TheEpoch_5} = ?MGR:trigger_react_to_env(Ma), {_, _, TheEpoch_5} = ?MGR:trigger_react_to_env(Ma),
@ -462,7 +469,7 @@ nonunanimous_setup_and_fix_test2() ->
MembersDict7 = machi_projection:make_members_dict(tl(P_s)), MembersDict7 = machi_projection:make_members_dict(tl(P_s)),
ok = machi_chain_manager1:set_chain_members( ok = machi_chain_manager1:set_chain_members(
Mb, ch_not_def_yet, TheEpoch_6, ap_mode, MembersDict7, []), Mb, ChainName, TheEpoch_6, ap_mode, MembersDict7, []),
Advance(), Advance(),
{_, _, TheEpoch_7} = ?MGR:trigger_react_to_env(Mb), {_, _, TheEpoch_7} = ?MGR:trigger_react_to_env(Mb),
@ -498,7 +505,7 @@ nonunanimous_setup_and_fix_test2() ->
MembersDict9 = machi_projection:make_members_dict(P_s), MembersDict9 = machi_projection:make_members_dict(P_s),
{_, _, TheEpoch_9} = ?MGR:trigger_react_to_env(Mb), {_, _, TheEpoch_9} = ?MGR:trigger_react_to_env(Mb),
ok = machi_chain_manager1:set_chain_members( ok = machi_chain_manager1:set_chain_members(
Mb, ch_not_def_yet, TheEpoch_9, ap_mode, MembersDict9, []), Mb, ChainName, TheEpoch_9, ap_mode, MembersDict9, []),
Advance(), Advance(),
{_, _, TheEpoch_9b} = ?MGR:trigger_react_to_env(Mb), {_, _, TheEpoch_9b} = ?MGR:trigger_react_to_env(Mb),
true = (TheEpoch_9b > TheEpoch_9), true = (TheEpoch_9b > TheEpoch_9),

View file

@ -30,6 +30,22 @@
-define(FLU, machi_flu1). -define(FLU, machi_flu1).
-define(FLU_C, machi_flu1_client). -define(FLU_C, machi_flu1_client).
get_env_vars(App, Ks) ->
Raw = [application:get_env(App, K) || K <- Ks],
Old = lists:zip(Ks, Raw),
{App, Old}.
clean_up_env_vars({App, Old}) ->
[case Res of
undefined ->
application:unset_env(App, K);
{ok, V} ->
application:set_env(App, K, V)
end || {K, Res} <- Old].
filter_env_var({ok, V}) -> V;
filter_env_var(Else) -> Else.
clean_up_data_dir(DataDir) -> clean_up_data_dir(DataDir) ->
[begin [begin
Fs = filelib:wildcard(DataDir ++ Glob), Fs = filelib:wildcard(DataDir ++ Glob),