test(cluster-rpc): ensure testsuite is side-effects-free
This commit is contained in:
parent
56eefe34d5
commit
ae79516fd2
|
@ -19,9 +19,9 @@
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
|
|
||||||
-include("emqx_conf.hrl").
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
|
||||||
-define(NODE1, emqx_cluster_rpc).
|
-define(NODE1, emqx_cluster_rpc).
|
||||||
-define(NODE2, emqx_cluster_rpc2).
|
-define(NODE2, emqx_cluster_rpc2).
|
||||||
-define(NODE3, emqx_cluster_rpc3).
|
-define(NODE3, emqx_cluster_rpc3).
|
||||||
|
@ -42,20 +42,25 @@ suite() -> [{timetrap, {minutes, 5}}].
|
||||||
groups() -> [].
|
groups() -> [].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
ok = emqx_common_test_helpers:start_apps([]),
|
Apps = emqx_cth_suite:start(
|
||||||
ok = mria:wait_for_tables(emqx_cluster_rpc:create_tables()),
|
[
|
||||||
ok = emqx_config:put([node, cluster_call, retry_interval], 1000),
|
emqx,
|
||||||
meck:new(emqx_alarm, [non_strict, passthrough, no_link]),
|
{emqx_conf,
|
||||||
meck:expect(emqx_alarm, activate, 3, ok),
|
"node.cluster_call {"
|
||||||
meck:expect(emqx_alarm, deactivate, 3, ok),
|
"\n retry_interval = 1s"
|
||||||
|
"\n max_history = 100"
|
||||||
|
"\n cleanup_interval = 500ms"
|
||||||
|
"\n}"}
|
||||||
|
],
|
||||||
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
|
),
|
||||||
meck:new(mria, [non_strict, passthrough, no_link]),
|
meck:new(mria, [non_strict, passthrough, no_link]),
|
||||||
meck:expect(mria, running_nodes, 0, [?NODE1, {node(), ?NODE2}, {node(), ?NODE3}]),
|
meck:expect(mria, running_nodes, 0, [?NODE1, {node(), ?NODE2}, {node(), ?NODE3}]),
|
||||||
Config.
|
[{suite_apps, Apps} | Config].
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(Config) ->
|
||||||
ok = emqx_common_test_helpers:stop_apps([]),
|
ok = meck:unload(mria),
|
||||||
meck:unload(emqx_alarm),
|
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||||
ok.
|
|
||||||
|
|
||||||
init_per_testcase(_TestCase, Config) ->
|
init_per_testcase(_TestCase, Config) ->
|
||||||
stop(),
|
stop(),
|
||||||
|
@ -67,7 +72,6 @@ end_per_testcase(_Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_base_test(_Config) ->
|
t_base_test(_Config) ->
|
||||||
emqx_cluster_rpc:reset(),
|
|
||||||
?assertEqual(emqx_cluster_rpc:status(), {atomic, []}),
|
?assertEqual(emqx_cluster_rpc:status(), {atomic, []}),
|
||||||
Pid = self(),
|
Pid = self(),
|
||||||
MFA = {M, F, A} = {?MODULE, echo, [Pid, test]},
|
MFA = {M, F, A} = {?MODULE, echo, [Pid, test]},
|
||||||
|
@ -94,7 +98,6 @@ t_base_test(_Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_commit_fail_test(_Config) ->
|
t_commit_fail_test(_Config) ->
|
||||||
emqx_cluster_rpc:reset(),
|
|
||||||
{atomic, []} = emqx_cluster_rpc:status(),
|
{atomic, []} = emqx_cluster_rpc:status(),
|
||||||
{M, F, A} = {?MODULE, failed_on_node, [erlang:whereis(?NODE2)]},
|
{M, F, A} = {?MODULE, failed_on_node, [erlang:whereis(?NODE2)]},
|
||||||
{init_failure, "MFA return not ok"} = multicall(M, F, A),
|
{init_failure, "MFA return not ok"} = multicall(M, F, A),
|
||||||
|
@ -102,7 +105,6 @@ t_commit_fail_test(_Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_commit_crash_test(_Config) ->
|
t_commit_crash_test(_Config) ->
|
||||||
emqx_cluster_rpc:reset(),
|
|
||||||
{atomic, []} = emqx_cluster_rpc:status(),
|
{atomic, []} = emqx_cluster_rpc:status(),
|
||||||
{M, F, A} = {?MODULE, no_exist_function, []},
|
{M, F, A} = {?MODULE, no_exist_function, []},
|
||||||
{init_failure, {error, Meta}} = multicall(M, F, A),
|
{init_failure, {error, Meta}} = multicall(M, F, A),
|
||||||
|
@ -150,7 +152,6 @@ t_commit_ok_but_apply_fail_on_other_node(_Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_commit_concurrency(_Config) ->
|
t_commit_concurrency(_Config) ->
|
||||||
emqx_cluster_rpc:reset(),
|
|
||||||
{atomic, []} = emqx_cluster_rpc:status(),
|
{atomic, []} = emqx_cluster_rpc:status(),
|
||||||
Pid = self(),
|
Pid = self(),
|
||||||
{BaseM, BaseF, BaseA} = {?MODULE, echo, [Pid, test]},
|
{BaseM, BaseF, BaseA} = {?MODULE, echo, [Pid, test]},
|
||||||
|
@ -211,7 +212,6 @@ receive_seq_msg(Acc) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
t_catch_up_status_handle_next_commit(_Config) ->
|
t_catch_up_status_handle_next_commit(_Config) ->
|
||||||
emqx_cluster_rpc:reset(),
|
|
||||||
{atomic, []} = emqx_cluster_rpc:status(),
|
{atomic, []} = emqx_cluster_rpc:status(),
|
||||||
{M, F, A} = {?MODULE, failed_on_node_by_odd, [erlang:whereis(?NODE1)]},
|
{M, F, A} = {?MODULE, failed_on_node_by_odd, [erlang:whereis(?NODE1)]},
|
||||||
{ok, 1, ok} = multicall(M, F, A, 1, 1000),
|
{ok, 1, ok} = multicall(M, F, A, 1, 1000),
|
||||||
|
@ -220,7 +220,6 @@ t_catch_up_status_handle_next_commit(_Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_commit_ok_apply_fail_on_other_node_then_recover(_Config) ->
|
t_commit_ok_apply_fail_on_other_node_then_recover(_Config) ->
|
||||||
emqx_cluster_rpc:reset(),
|
|
||||||
{atomic, []} = emqx_cluster_rpc:status(),
|
{atomic, []} = emqx_cluster_rpc:status(),
|
||||||
ets:new(test, [named_table, public]),
|
ets:new(test, [named_table, public]),
|
||||||
ets:insert(test, {other_mfa_result, failed}),
|
ets:insert(test, {other_mfa_result, failed}),
|
||||||
|
@ -247,7 +246,6 @@ t_commit_ok_apply_fail_on_other_node_then_recover(_Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_del_stale_mfa(_Config) ->
|
t_del_stale_mfa(_Config) ->
|
||||||
emqx_cluster_rpc:reset(),
|
|
||||||
{atomic, []} = emqx_cluster_rpc:status(),
|
{atomic, []} = emqx_cluster_rpc:status(),
|
||||||
MFA = {M, F, A} = {io, format, ["test"]},
|
MFA = {M, F, A} = {io, format, ["test"]},
|
||||||
Keys = lists:seq(1, 50),
|
Keys = lists:seq(1, 50),
|
||||||
|
@ -289,7 +287,6 @@ t_del_stale_mfa(_Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_skip_failed_commit(_Config) ->
|
t_skip_failed_commit(_Config) ->
|
||||||
emqx_cluster_rpc:reset(),
|
|
||||||
{atomic, []} = emqx_cluster_rpc:status(),
|
{atomic, []} = emqx_cluster_rpc:status(),
|
||||||
{ok, 1, ok} = multicall(io, format, ["test~n"], all, 1000),
|
{ok, 1, ok} = multicall(io, format, ["test~n"], all, 1000),
|
||||||
ct:sleep(180),
|
ct:sleep(180),
|
||||||
|
@ -310,7 +307,6 @@ t_skip_failed_commit(_Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_fast_forward_commit(_Config) ->
|
t_fast_forward_commit(_Config) ->
|
||||||
emqx_cluster_rpc:reset(),
|
|
||||||
{atomic, []} = emqx_cluster_rpc:status(),
|
{atomic, []} = emqx_cluster_rpc:status(),
|
||||||
{ok, 1, ok} = multicall(io, format, ["test~n"], all, 1000),
|
{ok, 1, ok} = multicall(io, format, ["test~n"], all, 1000),
|
||||||
ct:sleep(180),
|
ct:sleep(180),
|
||||||
|
@ -358,12 +354,10 @@ tnx_ids(Status) ->
|
||||||
).
|
).
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
{ok, Pid1} = emqx_cluster_rpc:start_link(),
|
{ok, _Pid2} = emqx_cluster_rpc:start_link({node(), ?NODE2}, ?NODE2, 500),
|
||||||
{ok, Pid2} = emqx_cluster_rpc:start_link({node(), ?NODE2}, ?NODE2, 500),
|
{ok, _Pid3} = emqx_cluster_rpc:start_link({node(), ?NODE3}, ?NODE3, 500),
|
||||||
{ok, Pid3} = emqx_cluster_rpc:start_link({node(), ?NODE3}, ?NODE3, 500),
|
ok = emqx_cluster_rpc:reset(),
|
||||||
{ok, Pid4} = emqx_cluster_rpc_cleaner:start_link(100, 500),
|
ok.
|
||||||
true = erlang:register(emqx_cluster_rpc_cleaner, Pid4),
|
|
||||||
{ok, [Pid1, Pid2, Pid3, Pid4]}.
|
|
||||||
|
|
||||||
stop() ->
|
stop() ->
|
||||||
[
|
[
|
||||||
|
@ -376,7 +370,7 @@ stop() ->
|
||||||
erlang:exit(P, kill)
|
erlang:exit(P, kill)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|| N <- [?NODE1, ?NODE2, ?NODE3, emqx_cluster_rpc_cleaner]
|
|| N <- [?NODE2, ?NODE3]
|
||||||
].
|
].
|
||||||
|
|
||||||
receive_msg(0, _Msg) ->
|
receive_msg(0, _Msg) ->
|
||||||
|
|
Loading…
Reference in New Issue