diff options
| author | Ayanda Dube <ayanda.dube@erlang-solutions.com> | 2015-09-25 12:28:40 +0100 |
|---|---|---|
| committer | Ayanda Dube <ayanda.dube@erlang-solutions.com> | 2015-10-07 08:46:41 +0100 |
| commit | a97260c1905d7aecf6916071607a8bb770ef7dc9 (patch) | |
| tree | b1fa8a8b4cff45ad726d322d795943d4eddfa27d /test/src | |
| parent | 6d3ef5aa75fd45f4788085b8f89dc8b4e2697123 (diff) | |
| download | rabbitmq-server-git-a97260c1905d7aecf6916071607a8bb770ef7dc9.tar.gz | |
Moves 'rabbitmqctl' timeout successful tests to separate module.
References #62
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/rabbit_tests.erl | 31 | ||||
| -rw-r--r-- | test/src/timeout_tests.erl | 131 |
2 files changed, 162 insertions, 0 deletions
diff --git a/test/src/rabbit_tests.erl b/test/src/rabbit_tests.erl index c056c280fa..9a9ece6267 100644 --- a/test/src/rabbit_tests.erl +++ b/test/src/rabbit_tests.erl @@ -29,6 +29,7 @@ -define(TRANSIENT_MSG_STORE, msg_store_transient). -define(CLEANUP_QUEUE_NAME, <<"cleanup-queue">>). -define(TIMEOUT, 30000). +-define(TIMEOUT_LIST_OPS_PASS, 1000). all_tests() -> try @@ -76,6 +77,7 @@ all_tests0() -> passed = test_ha_policy_validation(), passed = test_queue_master_location_policy_validation(), passed = test_server_status(), + passed = timeout_tests:all_tests(), passed = test_amqp_connection_refusal(), passed = test_confirms(), passed = test_with_state(), @@ -1793,10 +1795,18 @@ dead_queue_loop(QueueName, OldPid) -> control_action(Command, Args) -> control_action(Command, node(), Args, default_options()). +control_action(Command, Args, Timeout) when is_number(Timeout) -> + control_action(Command, node(), Args, default_options(), Timeout); + control_action(Command, Args, NewOpts) -> control_action(Command, node(), Args, expand_options(default_options(), NewOpts)). +control_action(Command, Args, NewOpts, Timeout) when is_number(Timeout) -> + control_action(Command, node(), Args, + expand_options(default_options(), NewOpts), + Timeout); + control_action(Command, Node, Args, Opts) -> case catch rabbit_control_main:action( Command, Node, Args, Opts, @@ -1811,6 +1821,20 @@ control_action(Command, Node, Args, Opts) -> Other end. +control_action(Command, Node, Args, Opts, Timeout) when is_number(Timeout) -> + case catch rabbit_control_main:action( + Command, Node, Args, Opts, + fun (Format, Args1) -> + io:format(Format ++ " ...~n", Args1) + end, Timeout) of + ok -> + io:format("done.~n"), + ok; + Other -> + io:format("failed.~n"), + Other + end. + control_action_opts(Raw) -> NodeStr = atom_to_list(node()), case rabbit_control_main:parse_arguments(Raw, NodeStr) of @@ -1832,6 +1856,13 @@ info_action(Command, Args, CheckVHost) -> {bad_argument, dummy} = control_action(Command, ["dummy"]), ok. +info_action(Command, Args, CheckVHost, Timeout) when is_number(Timeout) -> + if CheckVHost -> ok = control_action(Command, [], ["-p", "/"], Timeout); + true -> ok + end, + ok = control_action(Command, lists:map(fun atom_to_list/1, Args), Timeout), + ok. + default_options() -> [{"-p", "/"}, {"-q", "false"}]. expand_options(As, Bs) -> diff --git a/test/src/timeout_tests.erl b/test/src/timeout_tests.erl new file mode 100644 index 0000000000..7ba6e80500 --- /dev/null +++ b/test/src/timeout_tests.erl @@ -0,0 +1,131 @@ +%% 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(timeout_tests). + +-compile([export_all]). + +-export([all_tests/0]). + +-import(rabbit_tests,[default_options/0, control_action/2, control_action/3, + control_action/4, control_action/5, control_action_opts/1, + test_channel/0, expand_options/2, find_listener/0, + info_action/4]). + +-include("rabbit.hrl"). + +-define(TIMEOUT_LIST_OPS_PASS, 1000). + +all_tests() -> + passed = test_list_operations_timeout_pass(), + passed. + +test_list_operations_timeout_pass() -> + %% create a few things so there is some useful information to list + {_Writer, Limiter, Ch} = test_channel(), + [Q, Q2] = [Queue || Name <- [<<"foo">>, <<"bar">>], + {new, Queue = #amqqueue{}} <- + [rabbit_amqqueue:declare( + rabbit_misc:r(<<"/">>, queue, Name), + false, false, [], none)]], + ok = rabbit_amqqueue:basic_consume( + Q, true, Ch, Limiter, false, 0, <<"ctag">>, true, [], undefined), + + %% list users + ok = control_action(add_user, ["foo", "bar"]), + {error, {user_already_exists, _}} = + control_action(add_user, ["foo", "bar"]), + ok = control_action(list_users, [], ?TIMEOUT_LIST_OPS_PASS), + + %% list parameters + ok = rabbit_runtime_parameters_test:register(), + ok = control_action(set_parameter, ["test", "good", "123"]), + ok = control_action(list_parameters, [], ?TIMEOUT_LIST_OPS_PASS), + ok = control_action(clear_parameter, ["test", "good"]), + rabbit_runtime_parameters_test:unregister(), + + %% list vhosts + ok = control_action(add_vhost, ["/testhost"]), + {error, {vhost_already_exists, _}} = + control_action(add_vhost, ["/testhost"]), + ok = control_action(list_vhosts, [], ?TIMEOUT_LIST_OPS_PASS), + + %% list permissions + ok = control_action(set_permissions, ["foo", ".*", ".*", ".*"], + [{"-p", "/testhost"}]), + ok = control_action(list_permissions, [], [{"-p", "/testhost"}], + ?TIMEOUT_LIST_OPS_PASS), + + %% list user permissions + ok = control_action(list_user_permissions, ["foo"], + ?TIMEOUT_LIST_OPS_PASS), + + %% list policies + ok = control_action_opts(["set_policy", "name", ".*", + "{\"ha-mode\":\"all\"}"]), + ok = control_action(list_policies, [], ?TIMEOUT_LIST_OPS_PASS), + ok = control_action(clear_policy, ["name"]), + + %% list queues + ok = info_action(list_queues, rabbit_amqqueue:info_keys(), false, + ?TIMEOUT_LIST_OPS_PASS), + + %% list exchanges + ok = info_action(list_exchanges, rabbit_exchange:info_keys(), true, + ?TIMEOUT_LIST_OPS_PASS), + + %% list bindings + ok = info_action(list_bindings, rabbit_binding:info_keys(), true, + ?TIMEOUT_LIST_OPS_PASS), + + %% list connections + {H, P} = find_listener(), + {ok, C} = gen_tcp:connect(H, P, []), + gen_tcp:send(C, <<"AMQP", 0, 0, 9, 1>>), + timer:sleep(100), + ok = info_action(list_connections, + rabbit_networking:connection_info_keys(), + false, + ?TIMEOUT_LIST_OPS_PASS), + + %% list consumers + ok = info_action(list_consumers, rabbit_amqqueue:consumer_info_keys(), + false, ?TIMEOUT_LIST_OPS_PASS), + + %% list channels + ok = info_action(list_channels, rabbit_channel:info_keys(), false, + ?TIMEOUT_LIST_OPS_PASS), + + %% do some cleaning up + ok = control_action(delete_user, ["foo"]), + {error, {no_such_user, _}} = + control_action(delete_user, ["foo"]), + + ok = control_action(delete_vhost, ["/testhost"]), + {error, {no_such_vhost, _}} = + control_action(delete_vhost, ["/testhost"]), + + %% close_connection + [ConnPid] = rabbit_networking:connections(), + ok = control_action(close_connection, [rabbit_misc:pid_to_string(ConnPid), + "go away"]), + + %% cleanup queues + [{ok, _} = rabbit_amqqueue:delete(QR, false, false) || QR <- [Q, Q2]], + + unlink(Ch), + ok = rabbit_channel:shutdown(Ch), + + passed. |
