diff --git a/src/escalus_ct.erl b/src/escalus_ct.erl index 4cf4042b..f144d72a 100644 --- a/src/escalus_ct.erl +++ b/src/escalus_ct.erl @@ -15,9 +15,6 @@ get_config/1, log_stanza/3]). -%% What about that? --export([rpc_call/6]). - -define(APPNAME, escalus). -spec add_log_link(any(), any(), any()) -> ok | false. @@ -69,24 +66,6 @@ interpret_config_file_path(RelPath) -> error({escalus_error, beam_not_loaded}) end. -rpc_call(Node, Module, Function, Args, TimeOut, Cookie) -> - case is_ct_available() of - true -> - Result = ct_rpc:call(Node, Module, Function, Args, TimeOut, Cookie), - case Result of - {badrpc, Reason} -> - ct:pal("issue=rpc_call_failed " - "node=~p function=~p:~p reason=~p", - [Node, Module, Function, Reason]); - _ -> - ok - end, - Result; - false -> - %% TODO: don't error out, should be easy to simulate ct_rpc:call/6 - error({escalus_error, common_test_unavailable}) - end. - -spec log_stanza(undefined | binary(), in | out, exml_stream:element()) -> ok. log_stanza(undefined, _, _) -> ok; log_stanza(Jid, Direction, Stanza) -> diff --git a/src/escalus_ejabberd.erl b/src/escalus_ejabberd.erl index d487abc0..099c37bd 100644 --- a/src/escalus_ejabberd.erl +++ b/src/escalus_ejabberd.erl @@ -20,13 +20,16 @@ -module(escalus_ejabberd). -behaviour(escalus_user_db). - -%% escalus_user_db callbacks -export([start/1, stop/1, create_users/2, delete_users/2]). +-behaviour(escalus_server). +-export([pre_story/1, + post_story/1, + name/0]). + -export([rpc/3, remote_display/1, remote_format/1, @@ -55,7 +58,7 @@ rpc(M, F, A) -> Node = escalus_ct:get_config(ejabberd_node), Cookie = escalus_ct:get_config(ejabberd_cookie), - escalus_ct:rpc_call(Node, M, F, A, 3000, Cookie). + escalus_rpc:call(Node, M, F, A, 3000, Cookie). remote_display(String) -> Line = [$\n, [$- || _ <- String], $\n], @@ -216,6 +219,16 @@ delete_users(Config, Users) -> end, Users), Config. +%%-------------------------------------------------------------------- +%% escalus_server callbacks +%%-------------------------------------------------------------------- + +pre_story(Config) -> Config. + +post_story(Config) -> Config. + +name() -> ?MODULE. + %%-------------------------------------------------------------------- %% Helpers %%-------------------------------------------------------------------- diff --git a/src/escalus_mongooseim.erl b/src/escalus_mongooseim.erl index e2be413d..4478978c 100644 --- a/src/escalus_mongooseim.erl +++ b/src/escalus_mongooseim.erl @@ -140,4 +140,4 @@ check_metric_change({{Metric, Changes}, Before, After}, Acc) when is_list(Change check_change(Before, After, Change) when is_atom(Change) -> erlang:apply(erlang, Change, [After, Before]); check_change(Before, After, Change) when is_integer(Change) -> - After == Before + Change. \ No newline at end of file + After == Before + Change. diff --git a/src/escalus_rpc.erl b/src/escalus_rpc.erl new file mode 100644 index 00000000..ab112c4d --- /dev/null +++ b/src/escalus_rpc.erl @@ -0,0 +1,47 @@ +%% @doc This module should not exist as it has nothing to do with XMPP +%% nor is it needed by Escalus itself. +%% +%% The module contains RPC helpers which used to rely on Common Test, +%% but do not do so anymore. +-module(escalus_rpc). + +%% Public +-export([call/6]). + +%% +%% Public +%% + +%% @doc Emulate `ct_rpc:call/6' but do not rely on Common Test. +%% `call/6' takes a `Cookie' as the last parameter, +%% so that nodes with different cookies can be easily called. +%% However, this function is not safe (and neither is the original `ct_rpc:call/6') +%% in a concurrent environment as it gets/sets the cookie +%% with `erlang:get_cookie/0' and `erlang:set_cookie/1'. +%% Interleaving these calls in concurrent processes is prone to race conditions. +call(Node, Module, Function, Args, TimeOut, Cookie) -> + call_with_cookie_match(Node, Module, Function, Args, TimeOut, Cookie). + +%% +%% Internal +%% + +%% Copied from ct_rpc and renamed. +call_with_cookie_match(Node, Module, Function, Args, TimeOut, Cookie) when is_atom(Node) -> + Cookie0 = set_the_cookie(Cookie), + Result = case rpc:call(Node, Module, Function, Args, TimeOut) of + {badrpc, Reason} -> + error({badrpc, Reason}, [Node, Module, Function, Args, TimeOut, Cookie]); + R -> + R + end, + _ = set_the_cookie(Cookie0), + Result. + +%% Copied from ct_rpc. +set_the_cookie([]) -> + []; +set_the_cookie(Cookie) -> + Cookie0 = erlang:get_cookie(), + erlang:set_cookie(node(),Cookie), + Cookie0.