-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partial RPC cleanup in big tests #1846
Conversation
This is a fixup for f8a01ae, which extracted some stuff to `s2s_helper`.
Commits refactoring the rest of the suites will follow.
Codecov Report
@@ Coverage Diff @@
## master #1846 +/- ##
==========================================
- Coverage 74.59% 74.58% -0.02%
==========================================
Files 298 298
Lines 27957 27957
==========================================
- Hits 20855 20851 -4
- Misses 7102 7106 +4
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that the main (and only) way of using rpc from tests is distributed_helper:rpc/4
, right?
There are still some places where you changed from old escalus_ct:rpc_call
to escalus_rpc:call
, I guess this was on purpose.
@@ -46,16 +50,15 @@ message_test_cases() -> | |||
]. | |||
|
|||
suite() -> | |||
escalus:suite(). | |||
require_rpc_nodes([mim]) ++ escalus:suite(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's good idea!
%% RPCResult = rpc(mim(), remote_mod, remote_fun, [arg1, arg2]), | ||
%% ... | ||
%% | ||
require_rpc_nodes(Nodes) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it makes sens to ping these required nodes and fail the SUITE if any of them is not running. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for Michal's comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm against hiding IO in a function which is now completely declarative. We will know if a node is down anyway, because the RPC calls now throw instead of just returning an error by value and we will know with better granularity (the specific file, test and line).
|
||
stop(Domain, Mod) -> | ||
Node = escalus_ct:get_config(ejabberd_node), | ||
stop(Node, Domain, Mod). | ||
|
||
stop(Node, Domain, Mod) -> | ||
Cookie = escalus_ct:get_config(ejabberd_cookie), | ||
IsLoaded = escalus_ct:rpc_call(Node, gen_mod, is_loaded, [Domain, Mod], 5000, Cookie), | ||
IsLoaded = escalus_rpc:call(Node, gen_mod, is_loaded, [Domain, Mod], 5000, Cookie), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like 2 ways of using rpc
is mixed in this module. The one imported from distributed_helper
and direct use of escalus_rpc:call
. Are you going to unify it in this PR or is there a reason to do so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for Michal's comment.
I changed I think we should gather the remaining points into an issue on Redmine to groom (including @arcusfelis' idea mentioned here: https://github.com/esl/escalus/pull/170/files/29a600038330c08fa8c44ecacf0f501d9710dc35). |
I agree better merge these changes and improve it later. |
%% RPCResult = rpc(mim(), remote_mod, remote_fun, [arg1, arg2]), | ||
%% ... | ||
%% | ||
require_rpc_nodes(Nodes) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for Michal's comment.
|
||
stop(Domain, Mod) -> | ||
Node = escalus_ct:get_config(ejabberd_node), | ||
stop(Node, Domain, Mod). | ||
|
||
stop(Node, Domain, Mod) -> | ||
Cookie = escalus_ct:get_config(ejabberd_cookie), | ||
IsLoaded = escalus_ct:rpc_call(Node, gen_mod, is_loaded, [Domain, Mod], 5000, Cookie), | ||
IsLoaded = escalus_rpc:call(Node, gen_mod, is_loaded, [Domain, Mod], 5000, Cookie), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for Michal's comment.
JID = escalus_utils:jid_to_lower(<<Username/binary, "@", Domain/binary >>), | ||
lists:any(fun | ||
([RosterJID, Nick, Sub, "none", Group]) -> | ||
([RosterJID, __Nick, __Sub, "none", __Group]) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the aim of this function was to verify that Nick
, Sub
and Group
match the ones from the outer loop so the shadowing should be fixed instead of ignored. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the aim was to filter the elements with "none"
.
Shadowing excludes pattern matching, so it couldn't work the way you suggest. For example:
-module(shadow).
-compile([export_all]).
test() ->
L = [A, B] = [1, 2],
io:format("~p\n", [lists:filter(fun (A) -> true;
(_) -> false end, L)]).
The test shows:
10:22:18 erszcz @ x4 : /tmp
$ erlc shadow.erl
shadow.erl:2: Warning: export_all flag enabled - all functions will be exported
shadow.erl:5: Warning: variable 'A' is unused
shadow.erl:5: Warning: variable 'B' is unused
shadow.erl:6: Warning: variable 'A' is unused
shadow.erl:6: Warning: variable 'A' shadowed in 'fun'
shadow.erl:7: Warning: this clause cannot match because a previous clause at line 6 always matches
10:22:20 erszcz @ x4 : /tmp
$ erl
Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [kernel-poll:false]
Enabled docsh from: /Users/erszcz/work/erszcz/docsh/_build/default/lib/docsh
Call h(docsh) for interactive help.
Eshell V9.2 (abort with ^G)
1> shadow:test().
[1,2]
ok
2>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultimately, you're right about the intention (the function was initially introduced in esl/ejabberd_tests@09438c5a#diff-217f8e16b78b791f657c1119ea504f64R519), but I think that since esl/ejabberd_tests@95f4794a#diff-217f8e16b78b791f657c1119ea504f64R670 it doesn't match on Nick
, Sub
, or Group
.
@@ -49,7 +49,7 @@ disconnect_components(Components, Addr) -> | |||
rpc(M, F, A) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not distributed_helper:rpc/4
?
ejabberdctl(Cmd, Args, Config) -> | ||
Node = mim(), | ||
ejabberdctl(Node, Cmd, Args, Config). | ||
ejabberdctl(Node, Cmd, Args, Config). | ||
|
||
ejabberdctl(Node, Cmd, Args, Config) -> | ||
CtlCmd = distributed_helper:ctl_path(Node, Config), | ||
run(string:join([CtlCmd, Cmd | normalize_args(Args)], " ")). | ||
|
||
rpc_call(M, F, Args) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can deduplicate it with mongoose_helper:successful_rpc/3
?
big_tests/tests/mam_helper.erl
Outdated
@@ -950,7 +953,7 @@ parse_messages(Messages) -> | |||
|
|||
bootstrap_archive(Config) -> | |||
random:seed(os:timestamp()), | |||
Users = escalus_ct:get_config(escalus_users), | |||
_Users = escalus_ct:get_config(escalus_users), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... so we don't need this line at all, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's obviously a leftover from a debug print/log that somebody's forgotten to remove. I just figured it might be convenient to leave it in case of future debugging, but yes - let's remove it.
@@ -273,7 +273,7 @@ start_publish_listener(Config) -> | |||
rpc(M, F, A) -> | |||
Node = ct:get_config({hosts, mim, node}), | |||
Cookie = escalus_ct:get_config(ejabberd_cookie), | |||
escalus_ct:rpc_call(Node, M, F, A, 10000, Cookie). | |||
escalus_rpc:call(Node, M, F, A, 10000, Cookie). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not distributed_helper:rpc/4
?
wait_for(Label, Pred) -> | ||
wait_for(Label, Pred, timer:seconds(5)). | ||
|
||
wait_for(Label, _Pred, RemainingTime) when RemainingTime =< 0 -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost duplicate of mongoose_helper:wait_until
.
big_tests/tests/muc_helper.erl
Outdated
true -> odbc; | ||
false -> mnesia | ||
end, | ||
_Backend = case mongoose_helper:is_odbc_enabled(<<"localhost">>) of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or simply remove _Backend =
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as _Users
above.
@@ -366,7 +366,7 @@ parse_form(Fields) when is_list(Fields) -> | |||
rpc(M, F, A) -> | |||
Node = ct:get_config({hosts, mim, node}), | |||
Cookie = escalus_ct:get_config(ejabberd_cookie), | |||
escalus_ct:rpc_call(Node, M, F, A, 10000, Cookie). | |||
escalus_rpc:call(Node, M, F, A, 10000, Cookie). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not distributed_helper:rpc
?
@fenek I've addressed some issues with commits and some with comments. This PR is an extra to the task of decreasing reliance of Escalus on Common Test, not a result of targeted effort to completely clean up RPC in big tests - one step at a time. As I've suggested above we should have a separate issue for complete RPC cleanup, groom it and then resolve as appropriate. The main pain point is that there's currently an unrelated problem in MUC HTTP API suite which requires like 10 Travis restarts, so I don't want to add anything that requires a CI rerun to this particular PR. |
|
I'm keeping my stance that we should not do it.
#1853 created.
Apart from |
OK, please create a ticket for this as well. Anyway, I think we need one last Travis confirmation anyway, correct? Last commit has |
Just created #1855 |
All the commits after 32badd4 have I think they are simple enough to assume correctness and we'll need to do the job restart magic on master anyway after the PR is merged. |
This PR tests Escalus with changes from esl/escalus#170 as well as somewhat cleans up the way RPC is done in big tests.
With regard to RPC in big tests, this is not complete. There are still things which require refactoring:
escalus_ejabberd
calls which hide RPC in the library, but by default access a particular noderpc_apply
inmam_SUITE
escalus_ejabberd
, but not callingescalus_ejabberd:rpc
directly - these cases weren't caught bysed
grep rpc
orrg rpc
inbig_tests/
should give hints.These bullet points do not suggest this stuff should go into this PR. Rather, than even when this PR is merged, the cleanup won't be complete yet.