From cfc29e7615ec0a93ac0be619d33609c2139b57fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Costas=20S=C3=A1nchez?= Date: Tue, 31 May 2022 18:17:19 +0200 Subject: [PATCH] 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 --- include/proper_internal.hrl | 22 ++++++++++++++++++++++ src/proper.erl | 27 +++++++++++++-------------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/include/proper_internal.hrl b/include/proper_internal.hrl index 709388fc..ecb7133f 100644 --- a/include/proper_internal.hrl +++ b/include/proper_internal.hrl @@ -27,6 +27,28 @@ -include("proper_common.hrl"). +%%------------------------------------------------------------------------------ +%% Peer node module definition +%%------------------------------------------------------------------------------ + +-if (?OTP_RELEASE >= 25). +-define(CASE_START_PEER_NODE(Name), + case peer:start_link(#{name => Name}) of + {ok, Pid, Node} -> + register(Node, Pid), + _ = update_worker_node_ref({Node, {already_running, false}}), + Node;). +-define(STOP_PEER_NODE(Name), + peer:stop(Name)). +-else. +-define(CASE_START_PEER_NODE(Name), + case slave:start_link(_HostName = list_to_atom(net_adm:localhost()), Name) of + {ok, Node} -> + _ = update_worker_node_ref({Node, {already_running, false}}), + Node;). +-define(STOP_PEER_NODE(Name), + slave:stop(Node)). +-endif. %%------------------------------------------------------------------------------ %% Random generator selection diff --git a/src/proper.erl b/src/proper.erl index 26200ab2..445790ee 100644 --- a/src/proper.erl +++ b/src/proper.erl @@ -2400,14 +2400,8 @@ update_worker_node_ref(NodeName) -> %% @doc Starts a remote node to ensure the testing will not %% crash the BEAM, and loads on it all the needed code. -spec start_node(node()) -> node(). -start_node(SlaveName) -> - [] = os:cmd("epmd -daemon"), - HostName = list_to_atom(net_adm:localhost()), - _ = net_kernel:start([proper_master, shortnames]), - case slave:start_link(HostName, SlaveName) of - {ok, Node} -> - _ = update_worker_node_ref({Node, {already_running, false}}), - Node; +start_node(Name) -> + ?CASE_START_PEER_NODE(Name) %% the 'ok' case of this case statement is in the macro {error, {already_running, Node}} -> _ = update_worker_node_ref({Node, {already_running, true}}), Node @@ -2466,20 +2460,25 @@ ensure_code_loaded(Nodes) -> %% @doc Starts multiple (NumNodes) remote nodes. -spec start_nodes(non_neg_integer()) -> [node()]. start_nodes(NumNodes) -> - [start_node(list_to_atom("proper_slave_" ++ integer_to_list(N))) + [] = os:cmd("epmd -daemon"), + _ = net_kernel:start([proper_leader, shortnames]), + [start_node(list_to_atom("proper_follower_" ++ integer_to_list(N))) || N <- lists:seq(1, NumNodes)]. +-spec stop_node({node(), {already_running, boolean()}}) -> ok. +stop_node({Node, {already_running, false}}) -> + ?STOP_PEER_NODE(Node); +stop_node({_Node, {already_running, true}}) -> + ok. + %% @private -%% @doc Stops all the registered (started) nodes. +%% @doc Stops all the registered (started by us) nodes. -spec stop_nodes() -> 'ok'. stop_nodes() -> case get(worker_nodes) of undefined -> ok; Nodes -> - StopFun = fun({Node, {already_running, false}}) -> slave:stop(Node); - ({_Node, {already_running, true}}) -> ok - end, - lists:foreach(StopFun, Nodes), + lists:foreach(fun stop_node/1, Nodes), _ = net_kernel:stop(), erase(worker_nodes), ok