Skip to content

Commit 1e7c6f4

Browse files
committed
Always call methods to be mocked externally
not only when running tests
1 parent 5e7ad46 commit 1e7c6f4

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

deps/rabbitmq_peer_discovery_aws/src/rabbit_peer_discovery_aws.erl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
-type filters() :: [{string(), string()}].
2121

2222
-ifdef(TEST).
23-
-compile(export_all).
24-
-define(LIST_NODES, ?MODULE:list_nodes). %% call externally such that meck can mock the function
25-
-else.
26-
-define(LIST_NODES, list_nodes).
23+
-compile(export_all).
2724
-endif.
2825

2926
-define(CONFIG_MODULE, rabbit_peer_discovery_config).
@@ -120,7 +117,8 @@ post_registration() ->
120117
-spec lock(Node :: node()) -> {ok, {ResourceId :: string(), LockRequesterId :: node()}} | {error, Reason :: string()}.
121118

122119
lock(Node) ->
123-
case ?LIST_NODES() of
120+
%% call list_nodes/0 externally such that meck can mock the function
121+
case ?MODULE:list_nodes() of
124122
{ok, {[], disc}} ->
125123
{error, "Cannot lock since no nodes got discovered."};
126124
{ok, {Nodes, disc}} ->
@@ -147,7 +145,7 @@ lock(Node) ->
147145
-spec unlock({ResourceId :: string(), LockRequesterId :: node()}) -> ok | {error, Reason :: string()}.
148146

149147
unlock(LockId) ->
150-
case ?LIST_NODES() of
148+
case ?MODULE:list_nodes() of
151149
{ok, {Nodes, disc}} ->
152150
global:del_lock(LockId, Nodes),
153151
ok;

deps/rabbitmq_peer_discovery_k8s/src/rabbit_peer_discovery_k8s.erl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
post_registration/0, lock/1, unlock/1, send_event/3, generate_v1_event/7]).
2020

2121
-ifdef(TEST).
22-
-compile(export_all).
23-
-define(LIST_NODES1, ?MODULE:list_nodes1). %% call externally such that meck can mock the function
24-
-else.
25-
-define(LIST_NODES1, list_nodes1).
22+
-compile(export_all).
2623
-endif.
2724

2825
%%
@@ -69,7 +66,8 @@ unregister() ->
6966
-spec lock(Node :: node()) -> {ok, {ResourceId :: string(), LockRequesterId :: node()}} | {error, Reason :: string()}.
7067

7168
lock(Node) ->
72-
case ?LIST_NODES1() of
69+
%% call list_nodes1/0 externally such that meck can mock the function
70+
case ?MODULE:list_nodes1() of
7371
{ok, Nodes} ->
7472
case lists:member(Node, Nodes) of
7573
true ->
@@ -95,7 +93,7 @@ lock(Node) ->
9593
-spec unlock({ResourceId :: string(), LockRequesterId :: node()}) -> ok | {error, Reason :: string()}.
9694

9795
unlock(LockId) ->
98-
case ?LIST_NODES1() of
96+
case ?MODULE:list_nodes1() of
9997
{ok, Nodes} ->
10098
global:del_lock(LockId, Nodes),
10199
ok;

0 commit comments

Comments
 (0)