Skip to content

Commit b4802a3

Browse files
committed
Use the peer module in tests
`slave` module is deprecated and will be removed rearrange exports to stop ELP from complaining about "unreachable tests" (exported helper functions)
1 parent da0c0f6 commit b4802a3

File tree

1 file changed

+42
-44
lines changed

1 file changed

+42
-44
lines changed

test/aten_SUITE.erl

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
-module(aten_SUITE).
22

3-
-compile(nowarn_export_all).
4-
-compile(export_all).
3+
-export([
4+
all/0,
5+
groups/0,
6+
init_per_group/2, end_per_group/2,
7+
init_per_testcase/2, end_per_testcase/2
8+
]).
9+
10+
-export([
11+
distribution_flood/1,
12+
detect_node_partition/1,
13+
detect_node_stop_start/1,
14+
unregister_does_not_detect/1,
15+
register_unknown_emits_down/1,
16+
register_detects_down/1,
17+
watchers_cleanup/1
18+
]).
519

620
-include_lib("common_test/include/ct.hrl").
721
-include_lib("eunit/include/eunit.hrl").
@@ -44,21 +58,12 @@ end_per_group(_, Config) ->
4458
Config.
4559

4660
init_per_testcase(_TestCase, Config) ->
47-
% try to stop all slaves
48-
[begin
49-
ok = aten:unregister(N),
50-
slave:stop(N)
51-
end || N <- nodes()],
5261
meck:new(aten_sink, [passthrough]),
5362
application:stop(aten),
5463
application:start(aten),
5564
Config.
5665

5766
end_per_testcase(_Case, _Config) ->
58-
[begin
59-
ok = aten:unregister(N),
60-
slave:stop(N)
61-
end || N <- nodes()],
6267
meck:unload(),
6368
ok.
6469

@@ -90,7 +95,7 @@ distribution_flood(_Config) ->
9095
after 5000 ->
9196
exit(node_event_timeout)
9297
end,
93-
{ok, S1} = start_slave(?FUNCTION_NAME),
98+
{ok, P1, S1} = start_peer(?FUNCTION_NAME),
9499
ct:pal("Node ~w Nodes ~w", [node(), nodes()]),
95100
receive
96101
{node_event, S1, up} -> ok
@@ -118,7 +123,7 @@ distribution_flood(_Config) ->
118123
ok
119124
after ?POLLINT + 20 ->
120125
flush(),
121-
ct_slave:stop(S1),
126+
peer:stop(P1),
122127
exit(unexpected_down)
123128
end
124129
after 60000 ->
@@ -129,7 +134,7 @@ distribution_flood(_Config) ->
129134
exit(LPid, normal),
130135
exit(SPid, normal),
131136
exit(EPid, normal),
132-
ct_slave:stop(S1),
137+
peer:stop(P1),
133138
ok.
134139

135140

@@ -141,7 +146,7 @@ detect_node_partition(_Config) ->
141146
after 5000 ->
142147
exit(node_event_timeout)
143148
end,
144-
{ok, S1} = start_slave(?FUNCTION_NAME),
149+
{ok, P1, S1} = start_peer(?FUNCTION_NAME),
145150
ct:pal("Node ~w Nodes ~w", [node(), nodes()]),
146151
receive
147152
{node_event, S1, up} -> ok
@@ -166,14 +171,14 @@ detect_node_partition(_Config) ->
166171
flush(),
167172
exit(node_event_timeout)
168173
end,
169-
ok = slave:stop(S1),
174+
ok = peer:stop(P1),
170175
ok = aten:unregister(S1),
171176
ok.
172177

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

187-
ok = slave:stop(S1),
192+
ok = peer:stop(P1),
188193
receive
189194
{node_event, S1, down} -> ok
190195
after 5000 ->
191196
exit(node_event_timeout)
192197
end,
193198

194-
{ok, S1} = start_slave(?FUNCTION_NAME),
199+
{ok, P2, S1} = start_peer(?FUNCTION_NAME),
195200
receive
196201
{node_event, S1, up} -> ok
197202
after 5000 ->
198203
exit(node_event_timeout)
199204
end,
200-
ok = slave:stop(S1),
205+
ok = peer:stop(P2),
201206
ok = aten:unregister(S1),
202207
ok.
203208

@@ -208,8 +213,8 @@ unregister_does_not_detect(_Config) ->
208213
ok = aten:register(S2),
209214
wait_for({node_event, S1, down}),
210215
wait_for({node_event, S2, down}),
211-
{ok, S1} = start_slave(?FUNCTION_NAME),
212-
{ok, S2} = start_slave(unregister_does_not_detect_2),
216+
{ok, P1, S1} = start_peer(?FUNCTION_NAME),
217+
{ok, P2, S2} = start_peer(unregister_does_not_detect_2),
213218
ct:pal("Node ~w Nodes ~w", [node(), nodes()]),
214219
wait_for({node_event, S1, up}),
215220
wait_for({node_event, S2, up}),
@@ -222,14 +227,14 @@ unregister_does_not_detect(_Config) ->
222227
gen_server:call(aten_detector, any),
223228
{monitored_by, MonByPidsAfter} = erlang:process_info(self(), monitored_by),
224229
?assertEqual(1, length([P || P <- MonByPidsAfter, P == DetectorPid])),
225-
ct_slave:stop(S1),
230+
peer:stop(P1),
226231
receive
227232
{node_event, S1, Evt} ->
228233
exit({unexpected_node_event, S1, Evt})
229234
after 1000 ->
230235
ok
231236
end,
232-
ct_slave:stop(S2),
237+
peer:stop(P2),
233238
wait_for({node_event, S2, down}),
234239
ok.
235240

@@ -252,7 +257,7 @@ register_detects_down(_Config) ->
252257
after 5000 ->
253258
exit(node_event_timeout)
254259
end,
255-
{ok, S1} = start_slave(?FUNCTION_NAME),
260+
{ok, P1, S1} = start_peer(?FUNCTION_NAME),
256261
receive
257262
{node_event, S1, up} -> ok
258263
after 5000 ->
@@ -276,7 +281,7 @@ register_detects_down(_Config) ->
276281
end,
277282
ok = aten:unregister(S1),
278283

279-
ct_slave:stop(S1),
284+
peer:stop(P1),
280285
ok.
281286

282287
watchers_cleanup(_Config) ->
@@ -295,7 +300,7 @@ watchers_cleanup(_Config) ->
295300
after 5000 ->
296301
exit(node_event_timeout)
297302
end,
298-
{ok, Node} = start_slave(?FUNCTION_NAME),
303+
{ok, Peer, Node} = start_peer(?FUNCTION_NAME),
299304
ct:pal("Node ~w Nodes ~w", [node(), nodes()]),
300305
receive
301306
{watcher_node_up, Node} -> ok
@@ -316,7 +321,7 @@ watchers_cleanup(_Config) ->
316321
Watcher ! stop,
317322

318323
timer:sleep(200),
319-
ok = slave:stop(Node),
324+
ok = peer:stop(Peer),
320325

321326
receive
322327
{watcher_node_down, Node} ->
@@ -381,23 +386,16 @@ search_paths() ->
381386
Ld = code:lib_dir(),
382387
lists:filter(fun (P) -> string:prefix(P, Ld) =:= nomatch end,
383388
code:get_path()).
384-
start_slave(N) ->
385-
{ok, Host} = get_current_host(),
386-
Pa = string:join(["-pa" | search_paths()], " "),
389+
start_peer(N) ->
390+
Pa = lists:join(" ", ["-pa" | search_paths()]),
387391
ct:pal("starting node ~w with ~s", [N, Pa]),
388-
%% boot_timeout is in seconds, apparently
389-
S = case ct_slave:start(Host, N, [{erl_flags, Pa},
390-
{boot_timeout, 10}]) of
391-
{ok, SN} -> SN;
392-
{error, started_not_connected, SN} ->
393-
SN
394-
end,
395-
_ = rpc:call(S, application, load, [aten]),
396-
rpc:call(S, application, set_env, [aten, poll_interval, ?POLLINT]),
397-
rpc:call(S, application, set_env, [aten, heartbeat_interval, ?HBINT]),
398-
rpc:call(S, application, set_env, [aten, scaling_factor, ?SCALE]),
399-
rpc:call(S, application, ensure_all_started, [aten]),
400-
{ok, S}.
392+
{ok, P, S} = ?CT_PEER(#{name => N, args => Pa, connection => standard_io}),
393+
ok = rpc:call(S, application, load, [aten]),
394+
ok = rpc:call(S, application, set_env, [aten, poll_interval, ?POLLINT]),
395+
ok = rpc:call(S, application, set_env, [aten, heartbeat_interval, ?HBINT]),
396+
ok = rpc:call(S, application, set_env, [aten, scaling_factor, ?SCALE]),
397+
{ok, _} = rpc:call(S, application, ensure_all_started, [aten]),
398+
{ok, P, S}.
401399

402400
after_char(_, []) -> [];
403401
after_char(Char, [Char|Rest]) -> Rest;

0 commit comments

Comments
 (0)