Fix fitness timing problem with short-circuit +trigger_early_adjustment/2

This commit is contained in:
Scott Lystig Fritchie 2015-12-08 15:27:47 +09:00
parent ef10ebed22
commit 27e8a31307
2 changed files with 25 additions and 29 deletions

View file

@ -39,7 +39,8 @@
get_unfit_list/1, update_local_down_list/3, get_unfit_list/1, update_local_down_list/3,
add_admin_down/3, delete_admin_down/2, add_admin_down/3, delete_admin_down/2,
send_fitness_update_spam/3, send_fitness_update_spam/3,
send_spam_to_everyone/1]). send_spam_to_everyone/1,
trigger_early_adjustment/2]).
%% 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,
@ -81,6 +82,13 @@ send_fitness_update_spam(Pid, FromName, Dict) ->
send_spam_to_everyone(Pid) -> send_spam_to_everyone(Pid) ->
gen_server:call(Pid, {send_spam_to_everyone}, infinity). gen_server:call(Pid, {send_spam_to_everyone}, infinity).
%% @doc For testing purposes, we don't want a test to wait for
%% wall-clock time to elapse before the fitness server makes a
%% down->up status decision.
trigger_early_adjustment(Pid, FLU) ->
Pid ! {adjust_down_list, FLU}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
init([{MyFluName}|Args]) -> init([{MyFluName}|Args]) ->
@ -95,13 +103,11 @@ init([{MyFluName}|Args]) ->
handle_call({get_unfit_list}, _From, #state{active_unfit=ActiveUnfit}=S) -> handle_call({get_unfit_list}, _From, #state{active_unfit=ActiveUnfit}=S) ->
Reply = ActiveUnfit, Reply = ActiveUnfit,
io:format(user, "get_unfit_list ~p: ~p\n", [S#state.my_flu_name, Reply]),
{reply, Reply, S}; {reply, Reply, S};
handle_call({update_local_down_list, Down, MembersDict}, _From, handle_call({update_local_down_list, Down, MembersDict}, _From,
#state{my_flu_name=MyFluName, pending_map=OldMap, #state{my_flu_name=MyFluName, pending_map=OldMap,
local_down=OldDown, members_dict=OldMembersDict, local_down=OldDown, members_dict=OldMembersDict,
admin_down=AdminDown}=S) -> admin_down=AdminDown}=S) ->
io:format(user, "update_local_down_list: ~w: down ~w md ~W\n", [S#state.my_flu_name, Down, MembersDict, 10]),
NewMap = store_in_map(OldMap, MyFluName, erlang:now(), Down, NewMap = store_in_map(OldMap, MyFluName, erlang:now(), Down,
AdminDown, [props_yo]), AdminDown, [props_yo]),
S2 = if Down == OldDown, MembersDict == OldMembersDict -> S2 = if Down == OldDown, MembersDict == OldMembersDict ->

View file

@ -356,11 +356,14 @@ nonunanimous_setup_and_fix_test2() ->
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 = fun() ->
[begin [begin
catch ?MGR:trigger_react_to_env(Mgr), [catch machi_fitness:trigger_early_adjustment(Fit, Tgt) ||
ok Fit <- [a_fitness,b_fitness,c_fitness],
end || _ <- lists:seq(1, 7), Tgt <- [a,b,c] ],
{Mgr,Proxy} <- MgrProxies] [catch ?MGR:trigger_react_to_env(Mgr) ||
{Mgr,_Proxy} <- MgrProxies],
ok
end || _ <- lists:seq(1, 3)]
end, end,
ok = machi_chain_manager1:set_chain_members(Ma, MembersDict), ok = machi_chain_manager1:set_chain_members(Ma, MembersDict),
ok = machi_chain_manager1:set_chain_members(Mb, MembersDict), ok = machi_chain_manager1:set_chain_members(Mb, MembersDict),
@ -498,32 +501,19 @@ nonunanimous_setup_and_fix_test2() ->
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, ch_not_def_yet, TheEpoch_9, ap_mode, MembersDict9, []),
Advance(), Advance(),
[begin
{ok, Pqq} = ?FLU_PC:read_latest_projection(Pxy, private),
io:format(user, "At ~w: ~w\n", [Pxy, machi_projection:make_summary(Pqq#projection_v1{dbg2=[]})])
end || Pxy <- tl(Proxies)],
{_, _, 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),
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
io:format(user, "STEP: Start a, and it joins like it ought to\n", []),
[{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} <- [hd(FluInfo)]], {Name,Port,Dir} <- [hd(FluInfo)]],
Advance(), Advance(),
os:cmd("touch /tmp/moomoo.c"), {ok, {false, {TheEpoch10,_}}} = ?FLU_PC:wedge_status(Proxy_a),
[begin {ok, {false, {TheEpoch10,_}}} = ?FLU_PC:wedge_status(Proxy_b),
Qzx = ?MGR:trigger_react_to_env(Mgr), {ok, {false, {TheEpoch10,_}}} = ?FLU_PC:wedge_status(Proxy_c),
io:format(user, "dbg: ~w: ~w\n", [Mgr, Qzx]), [{ok, #projection_v1{upi=[b], repairing=[c,a]}} =
ok
end || _ <- lists:seq(1,1),
{Mgr,Proxy} <- MgrProxies],
[begin
{ok, Pqq} = ?FLU_PC:read_latest_projection(Pxy, private),
io:format(user, "At ~w: ~w\n", [Pxy, machi_projection:make_summary(Pqq#projection_v1{dbg2=[]})])
end || Pxy <- Proxies],
[io:format(user, "Unfit @ ~w: ~p\n", [Xii, machi_fitness:get_unfit_list(machi_fitness)]) || Xii <- [a_fitness, b_fitness, c_fitness] ],
{ok, {true, {0,_}}} = ?FLU_PC:wedge_status(Proxy_a),
{_, _, TheEpoch_9c} = ?MGR:trigger_react_to_env(Ma),
{_, _, TheEpoch_9c} = ?MGR:trigger_react_to_env(Mb),
{_, _, TheEpoch_9c} = ?MGR:trigger_react_to_env(Mc),
[{ok, #projection_v1{upi=[b], repairing=[a,c]}} =
?FLU_PC:read_latest_projection(Pxy, private) || Pxy <- Proxies], ?FLU_PC:read_latest_projection(Pxy, private) || Pxy <- Proxies],
ok ok
after after