Skip to content

Commit

Permalink
Merge pull request #39 from rabbitmq/use-peer-module
Browse files Browse the repository at this point in the history
Use peer module in tests
  • Loading branch information
michaelklishin authored Feb 19, 2025
2 parents da0c0f6 + fa57ed8 commit d1c1ea8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 52 deletions.
4 changes: 0 additions & 4 deletions ci/travis.sh

This file was deleted.

90 changes: 42 additions & 48 deletions test/aten_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
-module(aten_SUITE).

-compile(nowarn_export_all).
-compile(export_all).
-export([
all/0,
groups/0,
init_per_group/2, end_per_group/2,
init_per_testcase/2, end_per_testcase/2
]).

-export([
distribution_flood/1,
detect_node_partition/1,
detect_node_stop_start/1,
unregister_does_not_detect/1,
register_unknown_emits_down/1,
register_detects_down/1,
watchers_cleanup/1
]).

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
Expand Down Expand Up @@ -44,21 +58,12 @@ end_per_group(_, Config) ->
Config.

init_per_testcase(_TestCase, Config) ->
% try to stop all slaves
[begin
ok = aten:unregister(N),
slave:stop(N)
end || N <- nodes()],
meck:new(aten_sink, [passthrough]),
application:stop(aten),
application:start(aten),
Config.

end_per_testcase(_Case, _Config) ->
[begin
ok = aten:unregister(N),
slave:stop(N)
end || N <- nodes()],
meck:unload(),
ok.

Expand Down Expand Up @@ -90,7 +95,7 @@ distribution_flood(_Config) ->
after 5000 ->
exit(node_event_timeout)
end,
{ok, S1} = start_slave(?FUNCTION_NAME),
{ok, P1, S1} = start_peer(?FUNCTION_NAME),
ct:pal("Node ~w Nodes ~w", [node(), nodes()]),
receive
{node_event, S1, up} -> ok
Expand Down Expand Up @@ -118,7 +123,7 @@ distribution_flood(_Config) ->
ok
after ?POLLINT + 20 ->
flush(),
ct_slave:stop(S1),
peer:stop(P1),
exit(unexpected_down)
end
after 60000 ->
Expand All @@ -129,7 +134,7 @@ distribution_flood(_Config) ->
exit(LPid, normal),
exit(SPid, normal),
exit(EPid, normal),
ct_slave:stop(S1),
peer:stop(P1),
ok.


Expand All @@ -141,7 +146,7 @@ detect_node_partition(_Config) ->
after 5000 ->
exit(node_event_timeout)
end,
{ok, S1} = start_slave(?FUNCTION_NAME),
{ok, P1, S1} = start_peer(?FUNCTION_NAME),
ct:pal("Node ~w Nodes ~w", [node(), nodes()]),
receive
{node_event, S1, up} -> ok
Expand All @@ -166,14 +171,14 @@ detect_node_partition(_Config) ->
flush(),
exit(node_event_timeout)
end,
ok = slave:stop(S1),
ok = peer:stop(P1),
ok = aten:unregister(S1),
ok.

detect_node_stop_start(_Config) ->
S1 = make_node_name(?FUNCTION_NAME),
ok = aten:register(S1),
{ok, S1} = start_slave(?FUNCTION_NAME),
{ok, P1, S1} = start_peer(?FUNCTION_NAME),
ct:pal("Node ~w Nodes ~w", [node(), nodes()]),
receive
{node_event, S1, up} -> ok
Expand All @@ -184,20 +189,20 @@ detect_node_stop_start(_Config) ->
%% give it enough time to generate more than one sample
timer:sleep(1000),

ok = slave:stop(S1),
ok = peer:stop(P1),
receive
{node_event, S1, down} -> ok
after 5000 ->
exit(node_event_timeout)
end,

{ok, S1} = start_slave(?FUNCTION_NAME),
{ok, P2, S1} = start_peer(?FUNCTION_NAME),
receive
{node_event, S1, up} -> ok
after 5000 ->
exit(node_event_timeout)
end,
ok = slave:stop(S1),
ok = peer:stop(P2),
ok = aten:unregister(S1),
ok.

Expand All @@ -208,8 +213,8 @@ unregister_does_not_detect(_Config) ->
ok = aten:register(S2),
wait_for({node_event, S1, down}),
wait_for({node_event, S2, down}),
{ok, S1} = start_slave(?FUNCTION_NAME),
{ok, S2} = start_slave(unregister_does_not_detect_2),
{ok, P1, S1} = start_peer(?FUNCTION_NAME),
{ok, P2, S2} = start_peer(unregister_does_not_detect_2),
ct:pal("Node ~w Nodes ~w", [node(), nodes()]),
wait_for({node_event, S1, up}),
wait_for({node_event, S2, up}),
Expand All @@ -222,14 +227,14 @@ unregister_does_not_detect(_Config) ->
gen_server:call(aten_detector, any),
{monitored_by, MonByPidsAfter} = erlang:process_info(self(), monitored_by),
?assertEqual(1, length([P || P <- MonByPidsAfter, P == DetectorPid])),
ct_slave:stop(S1),
peer:stop(P1),
receive
{node_event, S1, Evt} ->
exit({unexpected_node_event, S1, Evt})
after 1000 ->
ok
end,
ct_slave:stop(S2),
peer:stop(P2),
wait_for({node_event, S2, down}),
ok.

Expand All @@ -252,7 +257,7 @@ register_detects_down(_Config) ->
after 5000 ->
exit(node_event_timeout)
end,
{ok, S1} = start_slave(?FUNCTION_NAME),
{ok, P1, S1} = start_peer(?FUNCTION_NAME),
receive
{node_event, S1, up} -> ok
after 5000 ->
Expand All @@ -276,7 +281,7 @@ register_detects_down(_Config) ->
end,
ok = aten:unregister(S1),

ct_slave:stop(S1),
peer:stop(P1),
ok.

watchers_cleanup(_Config) ->
Expand All @@ -295,7 +300,7 @@ watchers_cleanup(_Config) ->
after 5000 ->
exit(node_event_timeout)
end,
{ok, Node} = start_slave(?FUNCTION_NAME),
{ok, Peer, Node} = start_peer(?FUNCTION_NAME),
ct:pal("Node ~w Nodes ~w", [node(), nodes()]),
receive
{watcher_node_up, Node} -> ok
Expand All @@ -316,7 +321,7 @@ watchers_cleanup(_Config) ->
Watcher ! stop,

timer:sleep(200),
ok = slave:stop(Node),
ok = peer:stop(Peer),

receive
{watcher_node_down, Node} ->
Expand Down Expand Up @@ -377,27 +382,16 @@ make_node_name(N) ->
{ok, Host} = get_current_host(),
list_to_atom(lists:flatten(io_lib:format("~s@~s", [N, Host]))).

search_paths() ->
Ld = code:lib_dir(),
lists:filter(fun (P) -> string:prefix(P, Ld) =:= nomatch end,
code:get_path()).
start_slave(N) ->
{ok, Host} = get_current_host(),
Pa = string:join(["-pa" | search_paths()], " "),
start_peer(N) ->
Pa = filename:dirname(code:which(aten)),
ct:pal("starting node ~w with ~s", [N, Pa]),
%% boot_timeout is in seconds, apparently
S = case ct_slave:start(Host, N, [{erl_flags, Pa},
{boot_timeout, 10}]) of
{ok, SN} -> SN;
{error, started_not_connected, SN} ->
SN
end,
_ = rpc:call(S, application, load, [aten]),
rpc:call(S, application, set_env, [aten, poll_interval, ?POLLINT]),
rpc:call(S, application, set_env, [aten, heartbeat_interval, ?HBINT]),
rpc:call(S, application, set_env, [aten, scaling_factor, ?SCALE]),
rpc:call(S, application, ensure_all_started, [aten]),
{ok, S}.
{ok, P, S} = ?CT_PEER(#{name => N, args => ["-pa", Pa]}),
ok = rpc:call(S, application, load, [aten]),
ok = rpc:call(S, application, set_env, [aten, poll_interval, ?POLLINT]),
ok = rpc:call(S, application, set_env, [aten, heartbeat_interval, ?HBINT]),
ok = rpc:call(S, application, set_env, [aten, scaling_factor, ?SCALE]),
{ok, _} = rpc:call(S, application, ensure_all_started, [aten]),
{ok, P, S}.

after_char(_, []) -> [];
after_char(Char, [Char|Rest]) -> Rest;
Expand Down

0 comments on commit d1c1ea8

Please sign in to comment.