Merge pull request #734 from basho/bugfix/demystify-overload

Refactor tests/overload to use less magical-number comparisons
This commit is contained in:
Andrew J. Stone 2015-02-11 17:57:44 -05:00
commit 42e7788f9d

View File

@ -77,14 +77,10 @@ test_no_overload_protection(_Nodes, _BKV, true) ->
ok; ok;
test_no_overload_protection(Nodes, BKV, ConsistentType) -> test_no_overload_protection(Nodes, BKV, ConsistentType) ->
lager:info("Testing with no overload protection"), lager:info("Testing with no overload protection"),
ProcFun = fun(X) -> ProcFun = build_predicate_gte(test_no_overload_protection, ?NUM_REQUESTS,
lager:info("in test_no_overload_protection ProcFun, Procs:~p, Metric:~p", [X, ?NUM_REQUESTS]), "ProcFun", "Procs"),
X >= ?NUM_REQUESTS QueueFun = build_predicate_gte(test_no_overload_protection, ?NUM_REQUESTS,
end, "QueueFun", "Queue Size"),
QueueFun = fun(X) ->
lager:info("in test_no_overload QueueFun, queue size:~p, Metric:~p", [X, ?NUM_REQUESTS]),
X >= ?NUM_REQUESTS
end,
verify_test_results(run_test(Nodes, BKV), ConsistentType, ProcFun, QueueFun). verify_test_results(run_test(Nodes, BKV), ConsistentType, ProcFun, QueueFun).
verify_test_results({_NumProcs, QueueLen}, true, _, QueueFun) -> verify_test_results({_NumProcs, QueueLen}, true, _, QueueFun) ->
@ -107,14 +103,8 @@ test_vnode_protection(Nodes, BKV, ConsistentType) ->
rt:pmap(fun(Node) -> rt:pmap(fun(Node) ->
rt:update_app_config(Node, Config) rt:update_app_config(Node, Config)
end, Nodes), end, Nodes),
ProcFun = fun(X) -> ProcFun = build_predicate_lt(test_vnode_protection, (?NUM_REQUESTS+1), "ProcFun", "Procs"),
lager:info("in test_vnode_protection ProcFun, Procs:~p, Metric:~p", [X, (2*?NUM_REQUESTS * 1.5)]), QueueFun = build_predicate_lt(test_vnode_protection, (?NUM_REQUESTS), "QueueFun", "QueueSize"),
X =< (2*?THRESHOLD * 1.5)
end,
QueueFun = fun(X) ->
lager:info("in test_vnode_protection QueueFun, QueueSize:~p, Metric:~p", [X, (?NUM_REQUESTS * 1.1)]),
X =< (?THRESHOLD * 1.1)
end,
verify_test_results(run_test(Nodes, BKV), ConsistentType, ProcFun, QueueFun), verify_test_results(run_test(Nodes, BKV), ConsistentType, ProcFun, QueueFun),
[Node1 | _] = Nodes, [Node1 | _] = Nodes,
@ -127,15 +117,10 @@ test_vnode_protection(Nodes, BKV, ConsistentType) ->
lager:info("Suspending vnode proxy for ~p", [Victim]), lager:info("Suspending vnode proxy for ~p", [Victim]),
Pid = suspend_vnode_proxy(Victim), Pid = suspend_vnode_proxy(Victim),
ProcFun2 = fun(X) -> ProcFun2 = build_predicate_gte("test_vnode_protection after suspend",
lager:info("in test_vnode_protection after suspend ProcFun, Procs:~p, Metric:~p", [X, ?NUM_REQUESTS]), (?NUM_REQUESTS), "ProcFun", "Procs"),
X >= ?NUM_REQUESTS QueueFun2 = build_predicate_lt("test_vnode_protection after suspend",
(?NUM_REQUESTS), "QueueFun", "QueueSize"),
end,
QueueFun2 = fun(X) ->
lager:info("in test_vnode_protection after suspend QueueFun, QueueSize:~p, Metric:~p", [X, (?THRESHOLD * 1.1)]),
X =< (?THRESHOLD * 1.1)
end,
verify_test_results(run_test(Nodes, BKV), ConsistentType, ProcFun2, QueueFun2), verify_test_results(run_test(Nodes, BKV), ConsistentType, ProcFun2, QueueFun2),
Pid ! resume, Pid ! resume,
ok. ok.
@ -147,14 +132,10 @@ test_fsm_protection(Nodes, BKV, ConsistentType) ->
rt:pmap(fun(Node) -> rt:pmap(fun(Node) ->
rt:update_app_config(Node, Config) rt:update_app_config(Node, Config)
end, Nodes), end, Nodes),
ProcFun = fun(X) -> ProcFun = build_predicate_lt(test_fsm_protection, (?NUM_REQUESTS),
lager:info("in test_fsm_protection ProcFun, Procs:~p, Metric:~p", [X, (?THRESHOLD * 1.1)]), "ProcFun", "Procs"),
X =< (?THRESHOLD * 1.2) QueueFun = build_predicate_lt(test_fsm_protection, (?NUM_REQUESTS),
end, "QueueFun", "QueueSize"),
QueueFun = fun(X) ->
lager:info("in test_fsm_protection QueueFun, QueueSize:~p, Metric:~p", [X, (?THRESHOLD * 1.1)]),
X =< (?THRESHOLD * 1.2)
end,
verify_test_results(run_test(Nodes, BKV), ConsistentType, ProcFun, QueueFun), verify_test_results(run_test(Nodes, BKV), ConsistentType, ProcFun, QueueFun),
ok. ok.
@ -490,3 +471,21 @@ remote_vnode_queue(Idx) ->
{ok, Pid} = riak_core_vnode_manager:get_vnode_pid(Idx, riak_kv_vnode), {ok, Pid} = riak_core_vnode_manager:get_vnode_pid(Idx, riak_kv_vnode),
{message_queue_len, Len} = process_info(Pid, message_queue_len), {message_queue_len, Len} = process_info(Pid, message_queue_len),
Len. Len.
%% In tests that do not expect work to be shed, we want to confirm that
%% at least ?NUM_REQUESTS (processes|queue entries) are handled.
build_predicate_gte(Test, Metric, Label, ValueLabel) ->
fun (X) ->
lager:info("in test ~p ~p, ~p:~p, expected no overload, Metric:>=~p",
[Test, Label, ValueLabel, X, Metric]),
X >= Metric
end.
%% In tests that expect work to be shed due to overload, the success
%% condition is simply that the number of (fsms|queue entries) is
%% less than ?NUM_REQUESTS.
build_predicate_lt(Test, Metric, Label, ValueLabel) ->
fun (X) ->
lager:info("in test ~p ~p, ~p:~p, expected overload, Metric:<~p",
[Test, Label, ValueLabel, X, Metric]),
X < Metric
end.