Skip to content

Commit cfc29e7

Browse files
authored
Address deprecation warnings in OTP25 (#294)
Address the deprecation of the old slave module in OTP 25.x. To do so, two new macros ?START_PEER_NODE/1 and ?STOP_PEER_NODE/1 have been added, which handle the node setup and teardown properly depending on the OTP version PropEr was compiled with. I also took the chance to improve the naming in the codebase around said nodes, and to make the code a bid cleaner. Fixes #293
1 parent 564283d commit cfc29e7

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

include/proper_internal.hrl

+22
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@
2727

2828
-include("proper_common.hrl").
2929

30+
%%------------------------------------------------------------------------------
31+
%% Peer node module definition
32+
%%------------------------------------------------------------------------------
33+
34+
-if (?OTP_RELEASE >= 25).
35+
-define(CASE_START_PEER_NODE(Name),
36+
case peer:start_link(#{name => Name}) of
37+
{ok, Pid, Node} ->
38+
register(Node, Pid),
39+
_ = update_worker_node_ref({Node, {already_running, false}}),
40+
Node;).
41+
-define(STOP_PEER_NODE(Name),
42+
peer:stop(Name)).
43+
-else.
44+
-define(CASE_START_PEER_NODE(Name),
45+
case slave:start_link(_HostName = list_to_atom(net_adm:localhost()), Name) of
46+
{ok, Node} ->
47+
_ = update_worker_node_ref({Node, {already_running, false}}),
48+
Node;).
49+
-define(STOP_PEER_NODE(Name),
50+
slave:stop(Node)).
51+
-endif.
3052

3153
%%------------------------------------------------------------------------------
3254
%% Random generator selection

src/proper.erl

+13-14
Original file line numberDiff line numberDiff line change
@@ -2400,14 +2400,8 @@ update_worker_node_ref(NodeName) ->
24002400
%% @doc Starts a remote node to ensure the testing will not
24012401
%% crash the BEAM, and loads on it all the needed code.
24022402
-spec start_node(node()) -> node().
2403-
start_node(SlaveName) ->
2404-
[] = os:cmd("epmd -daemon"),
2405-
HostName = list_to_atom(net_adm:localhost()),
2406-
_ = net_kernel:start([proper_master, shortnames]),
2407-
case slave:start_link(HostName, SlaveName) of
2408-
{ok, Node} ->
2409-
_ = update_worker_node_ref({Node, {already_running, false}}),
2410-
Node;
2403+
start_node(Name) ->
2404+
?CASE_START_PEER_NODE(Name) %% the 'ok' case of this case statement is in the macro
24112405
{error, {already_running, Node}} ->
24122406
_ = update_worker_node_ref({Node, {already_running, true}}),
24132407
Node
@@ -2466,20 +2460,25 @@ ensure_code_loaded(Nodes) ->
24662460
%% @doc Starts multiple (NumNodes) remote nodes.
24672461
-spec start_nodes(non_neg_integer()) -> [node()].
24682462
start_nodes(NumNodes) ->
2469-
[start_node(list_to_atom("proper_slave_" ++ integer_to_list(N)))
2463+
[] = os:cmd("epmd -daemon"),
2464+
_ = net_kernel:start([proper_leader, shortnames]),
2465+
[start_node(list_to_atom("proper_follower_" ++ integer_to_list(N)))
24702466
|| N <- lists:seq(1, NumNodes)].
24712467

2468+
-spec stop_node({node(), {already_running, boolean()}}) -> ok.
2469+
stop_node({Node, {already_running, false}}) ->
2470+
?STOP_PEER_NODE(Node);
2471+
stop_node({_Node, {already_running, true}}) ->
2472+
ok.
2473+
24722474
%% @private
2473-
%% @doc Stops all the registered (started) nodes.
2475+
%% @doc Stops all the registered (started by us) nodes.
24742476
-spec stop_nodes() -> 'ok'.
24752477
stop_nodes() ->
24762478
case get(worker_nodes) of
24772479
undefined -> ok;
24782480
Nodes ->
2479-
StopFun = fun({Node, {already_running, false}}) -> slave:stop(Node);
2480-
({_Node, {already_running, true}}) -> ok
2481-
end,
2482-
lists:foreach(StopFun, Nodes),
2481+
lists:foreach(fun stop_node/1, Nodes),
24832482
_ = net_kernel:stop(),
24842483
erase(worker_nodes),
24852484
ok

0 commit comments

Comments
 (0)