1
1
-module (aten_SUITE ).
2
2
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
+ ]).
5
19
6
20
-include_lib (" common_test/include/ct.hrl" ).
7
21
-include_lib (" eunit/include/eunit.hrl" ).
@@ -44,21 +58,12 @@ end_per_group(_, Config) ->
44
58
Config .
45
59
46
60
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 ()],
52
61
meck :new (aten_sink , [passthrough ]),
53
62
application :stop (aten ),
54
63
application :start (aten ),
55
64
Config .
56
65
57
66
end_per_testcase (_Case , _Config ) ->
58
- [begin
59
- ok = aten :unregister (N ),
60
- slave :stop (N )
61
- end || N <- nodes ()],
62
67
meck :unload (),
63
68
ok .
64
69
@@ -90,7 +95,7 @@ distribution_flood(_Config) ->
90
95
after 5000 ->
91
96
exit (node_event_timeout )
92
97
end ,
93
- {ok , S1 } = start_slave (? FUNCTION_NAME ),
98
+ {ok , P1 , S1 } = start_peer (? FUNCTION_NAME ),
94
99
ct :pal (" Node ~w Nodes ~w " , [node (), nodes ()]),
95
100
receive
96
101
{node_event , S1 , up } -> ok
@@ -118,7 +123,7 @@ distribution_flood(_Config) ->
118
123
ok
119
124
after ? POLLINT + 20 ->
120
125
flush (),
121
- ct_slave :stop (S1 ),
126
+ peer :stop (P1 ),
122
127
exit (unexpected_down )
123
128
end
124
129
after 60000 ->
@@ -129,7 +134,7 @@ distribution_flood(_Config) ->
129
134
exit (LPid , normal ),
130
135
exit (SPid , normal ),
131
136
exit (EPid , normal ),
132
- ct_slave :stop (S1 ),
137
+ peer :stop (P1 ),
133
138
ok .
134
139
135
140
@@ -141,7 +146,7 @@ detect_node_partition(_Config) ->
141
146
after 5000 ->
142
147
exit (node_event_timeout )
143
148
end ,
144
- {ok , S1 } = start_slave (? FUNCTION_NAME ),
149
+ {ok , P1 , S1 } = start_peer (? FUNCTION_NAME ),
145
150
ct :pal (" Node ~w Nodes ~w " , [node (), nodes ()]),
146
151
receive
147
152
{node_event , S1 , up } -> ok
@@ -166,14 +171,14 @@ detect_node_partition(_Config) ->
166
171
flush (),
167
172
exit (node_event_timeout )
168
173
end ,
169
- ok = slave :stop (S1 ),
174
+ ok = peer :stop (P1 ),
170
175
ok = aten :unregister (S1 ),
171
176
ok .
172
177
173
178
detect_node_stop_start (_Config ) ->
174
179
S1 = make_node_name (? FUNCTION_NAME ),
175
180
ok = aten :register (S1 ),
176
- {ok , S1 } = start_slave (? FUNCTION_NAME ),
181
+ {ok , P1 , S1 } = start_peer (? FUNCTION_NAME ),
177
182
ct :pal (" Node ~w Nodes ~w " , [node (), nodes ()]),
178
183
receive
179
184
{node_event , S1 , up } -> ok
@@ -184,20 +189,20 @@ detect_node_stop_start(_Config) ->
184
189
% % give it enough time to generate more than one sample
185
190
timer :sleep (1000 ),
186
191
187
- ok = slave :stop (S1 ),
192
+ ok = peer :stop (P1 ),
188
193
receive
189
194
{node_event , S1 , down } -> ok
190
195
after 5000 ->
191
196
exit (node_event_timeout )
192
197
end ,
193
198
194
- {ok , S1 } = start_slave (? FUNCTION_NAME ),
199
+ {ok , P2 , S1 } = start_peer (? FUNCTION_NAME ),
195
200
receive
196
201
{node_event , S1 , up } -> ok
197
202
after 5000 ->
198
203
exit (node_event_timeout )
199
204
end ,
200
- ok = slave :stop (S1 ),
205
+ ok = peer :stop (P2 ),
201
206
ok = aten :unregister (S1 ),
202
207
ok .
203
208
@@ -208,8 +213,8 @@ unregister_does_not_detect(_Config) ->
208
213
ok = aten :register (S2 ),
209
214
wait_for ({node_event , S1 , down }),
210
215
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 ),
213
218
ct :pal (" Node ~w Nodes ~w " , [node (), nodes ()]),
214
219
wait_for ({node_event , S1 , up }),
215
220
wait_for ({node_event , S2 , up }),
@@ -222,14 +227,14 @@ unregister_does_not_detect(_Config) ->
222
227
gen_server :call (aten_detector , any ),
223
228
{monitored_by , MonByPidsAfter } = erlang :process_info (self (), monitored_by ),
224
229
? assertEqual (1 , length ([P || P <- MonByPidsAfter , P == DetectorPid ])),
225
- ct_slave :stop (S1 ),
230
+ peer :stop (P1 ),
226
231
receive
227
232
{node_event , S1 , Evt } ->
228
233
exit ({unexpected_node_event , S1 , Evt })
229
234
after 1000 ->
230
235
ok
231
236
end ,
232
- ct_slave :stop (S2 ),
237
+ peer :stop (P2 ),
233
238
wait_for ({node_event , S2 , down }),
234
239
ok .
235
240
@@ -252,7 +257,7 @@ register_detects_down(_Config) ->
252
257
after 5000 ->
253
258
exit (node_event_timeout )
254
259
end ,
255
- {ok , S1 } = start_slave (? FUNCTION_NAME ),
260
+ {ok , P1 , S1 } = start_peer (? FUNCTION_NAME ),
256
261
receive
257
262
{node_event , S1 , up } -> ok
258
263
after 5000 ->
@@ -276,7 +281,7 @@ register_detects_down(_Config) ->
276
281
end ,
277
282
ok = aten :unregister (S1 ),
278
283
279
- ct_slave :stop (S1 ),
284
+ peer :stop (P1 ),
280
285
ok .
281
286
282
287
watchers_cleanup (_Config ) ->
@@ -295,7 +300,7 @@ watchers_cleanup(_Config) ->
295
300
after 5000 ->
296
301
exit (node_event_timeout )
297
302
end ,
298
- {ok , Node } = start_slave (? FUNCTION_NAME ),
303
+ {ok , Peer , Node } = start_peer (? FUNCTION_NAME ),
299
304
ct :pal (" Node ~w Nodes ~w " , [node (), nodes ()]),
300
305
receive
301
306
{watcher_node_up , Node } -> ok
@@ -316,7 +321,7 @@ watchers_cleanup(_Config) ->
316
321
Watcher ! stop ,
317
322
318
323
timer :sleep (200 ),
319
- ok = slave :stop (Node ),
324
+ ok = peer :stop (Peer ),
320
325
321
326
receive
322
327
{watcher_node_down , Node } ->
@@ -381,23 +386,16 @@ search_paths() ->
381
386
Ld = code :lib_dir (),
382
387
lists :filter (fun (P ) -> string :prefix (P , Ld ) =:= nomatch end ,
383
388
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 ()]),
387
391
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 }.
401
399
402
400
after_char (_ , []) -> [];
403
401
after_char (Char , [Char |Rest ]) -> Rest ;
0 commit comments