diff options
| author | Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com> | 2016-04-06 12:59:14 +0200 |
|---|---|---|
| committer | Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr> | 2016-05-27 10:37:28 +0200 |
| commit | 8dbc931d46eb85dfe5674bd5c1a16a5df2cf3161 (patch) | |
| tree | 87c249702c47b961f403b3784b8e418e5d0f19ae /test | |
| parent | becf2c7ecad6203d6b6705a0d32fdf3f7893bba3 (diff) | |
| download | rabbitmq-server-git-8dbc931d46eb85dfe5674bd5c1a16a5df2cf3161.tar.gz | |
rabbit_ct_broker_helpers: New helpers specific to the broker testsuite
In particular, it allows to run tests on the broker node itself.
References #725.
[#116526487]
Diffstat (limited to 'test')
| -rw-r--r-- | test/rabbit_ct_broker_helpers.erl | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/test/rabbit_ct_broker_helpers.erl b/test/rabbit_ct_broker_helpers.erl new file mode 100644 index 0000000000..52e3b67dd1 --- /dev/null +++ b/test/rabbit_ct_broker_helpers.erl @@ -0,0 +1,78 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved. +%% + +-module(rabbit_ct_broker_helpers). + +-include_lib("rabbit_common/include/rabbit.hrl"). + +-export([ + run_on_broker/4, + find_listener/0, + test_channel/0 + ]). + +run_on_broker(Node, Module, Function, Args) -> + %% We add some directories to the broker node search path. + Path1 = filename:dirname(code:which(Module)), + Path2 = filename:dirname(code:which(?MODULE)), + Paths = lists:usort([Path1, Path2]), + ExistingPaths = rpc:call(Node, code, get_path, []), + lists:foreach( + fun(P) -> + case lists:member(P, ExistingPaths) of + true -> ok; + false -> true = rpc:call(Node, code, add_pathz, [P]) + end + end, Paths), + %% If there is an exception, rpc:call/4 returns the exception as + %% a "normal" return value. If there is an exit signal, we raise + %% it again. In both cases, we have no idea of the module and line + %% number which triggered the issue. + case rpc:call(Node, Module, Function, Args) of + {badrpc, {'EXIT', Reason}} -> exit(Reason); + {badrpc, Reason} -> exit(Reason); + Ret -> Ret + end. + +find_listener() -> + [#listener{host = H, port = P} | _] = + [L || L = #listener{node = N, protocol = amqp} + <- rabbit_networking:active_listeners(), + N =:= node()], + {H, P}. + +user(Username) -> + #user{username = Username, + tags = [administrator], + authz_backends = [{rabbit_auth_backend_internal, none}]}. + +test_channel() -> + Me = self(), + Writer = spawn(fun () -> test_writer(Me) end), + {ok, Limiter} = rabbit_limiter:start_link(no_id), + {ok, Ch} = rabbit_channel:start_link( + 1, Me, Writer, Me, "", rabbit_framing_amqp_0_9_1, + user(<<"guest">>), <<"/">>, [], Me, Limiter), + {Writer, Limiter, Ch}. + +test_writer(Pid) -> + receive + {'$gen_call', From, flush} -> gen_server:reply(From, ok), + test_writer(Pid); + {send_command, Method} -> Pid ! Method, + test_writer(Pid); + shutdown -> ok + end. |
