|
| 1 | +%% The contents of this file are subject to the Mozilla Public License |
| 2 | +%% Version 1.1 (the "License"); you may not use this file except in |
| 3 | +%% compliance with the License. You may obtain a copy of the License |
| 4 | +%% at http://www.mozilla.org/MPL/ |
| 5 | +%% |
| 6 | +%% Software distributed under the License is distributed on an "AS IS" |
| 7 | +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
| 8 | +%% the License for the specific language governing rights and |
| 9 | +%% limitations under the License. |
| 10 | +%% |
| 11 | +%% The Original Code is RabbitMQ. |
| 12 | +%% |
| 13 | +%% The Initial Developer of the Original Code is GoPivotal, Inc. |
| 14 | +%% Copyright (c) 2016 Pivotal Software, Inc. All rights reserved. |
| 15 | +%% |
| 16 | +-module(health_check_SUITE). |
| 17 | + |
| 18 | +-include_lib("common_test/include/ct.hrl"). |
| 19 | +-include_lib("amqp_client/include/amqp_client.hrl"). |
| 20 | + |
| 21 | +-export([all/0 |
| 22 | + ,groups/0 |
| 23 | + ,init_per_suite/1 |
| 24 | + ,end_per_suite/1 |
| 25 | + ,init_per_testcase/2 |
| 26 | + ,end_per_testcase/2 |
| 27 | + ]). |
| 28 | + |
| 29 | +-export([ignores_remote_dead_channel/1 |
| 30 | + ,detects_local_dead_channel/1 |
| 31 | + ,ignores_remote_dead_queue/1 |
| 32 | + ,detects_local_dead_queue/1 |
| 33 | + ,ignores_remote_alarms/1 |
| 34 | + ,detects_local_alarm/1 |
| 35 | + ,honors_timeout_argument/1 |
| 36 | + ]). |
| 37 | + |
| 38 | +all() -> |
| 39 | + [{group, all_cases}]. |
| 40 | + |
| 41 | +groups() -> |
| 42 | + [{all_cases, [], |
| 43 | + [ignores_remote_dead_queue |
| 44 | + ,detects_local_dead_queue |
| 45 | + ,ignores_remote_dead_channel |
| 46 | + ,detects_local_dead_channel |
| 47 | + ,ignores_remote_alarms |
| 48 | + ,detects_local_alarm |
| 49 | + ,honors_timeout_argument |
| 50 | + ]}]. |
| 51 | + |
| 52 | +init_per_suite(Config) -> |
| 53 | + rabbit_ct_helpers:log_environment(), |
| 54 | + rabbit_ct_helpers:run_setup_steps(Config). |
| 55 | + |
| 56 | +end_per_suite(Config) -> |
| 57 | + rabbit_ct_helpers:run_teardown_steps(Config). |
| 58 | + |
| 59 | +init_per_testcase(Testcase, Config0) -> |
| 60 | + rabbit_ct_helpers:testcase_started(Config0, Testcase), |
| 61 | + Config1 = rabbit_ct_helpers:set_config( |
| 62 | + Config0, [{rmq_nodes_count, 2}, |
| 63 | + {rmq_nodes_clustered, true}]), |
| 64 | + rabbit_ct_helpers:run_steps(Config1, |
| 65 | + rabbit_ct_broker_helpers:setup_steps() ++ |
| 66 | + rabbit_ct_client_helpers:setup_steps()). |
| 67 | + |
| 68 | +end_per_testcase(Testcase, Config0) -> |
| 69 | + Config1 = case rabbit_ct_helpers:get_config(Config0, save_config) of |
| 70 | + undefined -> Config0; |
| 71 | + C -> C |
| 72 | + end, |
| 73 | + Config2 = rabbit_ct_helpers:run_steps(Config1, |
| 74 | + rabbit_ct_client_helpers:teardown_steps() ++ |
| 75 | + rabbit_ct_broker_helpers:teardown_steps()), |
| 76 | + rabbit_ct_helpers:testcase_finished(Config2, Testcase). |
| 77 | + |
| 78 | +%%---------------------------------------------------------------------------- |
| 79 | +%% Test cases |
| 80 | +%%---------------------------------------------------------------------------- |
| 81 | +ignores_remote_dead_channel(Config) -> |
| 82 | + [A, B] = open_channel_and_declare_queue_everywhere(Config), |
| 83 | + CPid = suspend_single_channel(Config, B), |
| 84 | + {ok, _} = rabbit_ct_broker_helpers:rabbitmqctl(Config, A, ["-t", "5", "node_health_check"]), |
| 85 | + resume_sys_process(Config, B, CPid), |
| 86 | + ok. |
| 87 | + |
| 88 | +detects_local_dead_channel(Config) -> |
| 89 | + [A|_] = open_channel_and_declare_queue_everywhere(Config), |
| 90 | + CPid = suspend_single_channel(Config, A), |
| 91 | + {error, 75, Str} = rabbit_ct_broker_helpers:rabbitmqctl(Config, A, ["-t", "5", "node_health_check"]), |
| 92 | + {match, _} = re:run(Str, "operation node_health_check.*timed out"), |
| 93 | + resume_sys_process(Config, A, CPid), |
| 94 | + ok. |
| 95 | + |
| 96 | +ignores_remote_dead_queue(Config) -> |
| 97 | + [A, B] = open_channel_and_declare_queue_everywhere(Config), |
| 98 | + QPid = suspend_single_queue(Config, B), |
| 99 | + {ok, _} = rabbit_ct_broker_helpers:rabbitmqctl(Config, A, ["-t", "5", "node_health_check"]), |
| 100 | + resume_sys_process(Config, B, QPid), |
| 101 | + ok. |
| 102 | + |
| 103 | +detects_local_dead_queue(Config) -> |
| 104 | + [A|_] = open_channel_and_declare_queue_everywhere(Config), |
| 105 | + QPid = suspend_single_queue(Config, A), |
| 106 | + {error, 75, Str} = rabbit_ct_broker_helpers:rabbitmqctl(Config, A, ["-t", "5", "node_health_check"]), |
| 107 | + {match, _} = re:run(Str, "operation node_health_check.*timed out"), |
| 108 | + resume_sys_process(Config, A, QPid), |
| 109 | + ok. |
| 110 | + |
| 111 | +ignores_remote_alarms(Config) -> |
| 112 | + [A, B] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename), |
| 113 | + rabbit_ct_broker_helpers:rabbitmqctl(Config, B, |
| 114 | + ["set_vm_memory_high_watermark", "0.000000001"]), |
| 115 | + {ok, _} = rabbit_ct_broker_helpers:rabbitmqctl(Config, A, ["-t", "5", "node_health_check"]), |
| 116 | + ok. |
| 117 | + |
| 118 | +detects_local_alarm(Config) -> |
| 119 | + [A|_] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename), |
| 120 | + rabbit_ct_broker_helpers:rabbitmqctl(Config, A, |
| 121 | + ["set_vm_memory_high_watermark", "0.000000001"]), |
| 122 | + {error, 70, Str} = rabbit_ct_broker_helpers:rabbitmqctl(Config, A, ["-t", "5", "node_health_check"]), |
| 123 | + {match, _} = re:run(Str, "resource alarm.*in effect"), |
| 124 | + ok. |
| 125 | + |
| 126 | +honors_timeout_argument(Config) -> |
| 127 | + [A|_] = open_channel_and_declare_queue_everywhere(Config), |
| 128 | + QPid = suspend_single_queue(Config, A), |
| 129 | + |
| 130 | + case timer:tc(rabbit_ct_broker_helpers, rabbitmqctl, [Config, A, ["-t", "5", "node_health_check"]]) of |
| 131 | + {TimeSpent, {error, 75, _}} -> |
| 132 | + if TimeSpent < 5000000 -> exit({too_fast, TimeSpent}); |
| 133 | + TimeSpent > 7000000 -> exit({too_slow, TimeSpent}); %% +2 seconds for rabbitmqctl overhead |
| 134 | + true -> ok |
| 135 | + end; |
| 136 | + {_, Unexpected} -> |
| 137 | + exit({unexpected, Unexpected}) |
| 138 | + end, |
| 139 | + resume_sys_process(Config, A, QPid), |
| 140 | + ok. |
| 141 | + |
| 142 | +%%---------------------------------------------------------------------------- |
| 143 | +%% Helpers |
| 144 | +%%---------------------------------------------------------------------------- |
| 145 | +open_channel_and_declare_queue_everywhere(Config) -> |
| 146 | + Nodes = rabbit_ct_broker_helpers:get_node_configs(Config, nodename), |
| 147 | + lists:foreach(fun(Node) -> |
| 148 | + Ch = rabbit_ct_client_helpers:open_channel(Config, Node), |
| 149 | + #'queue.declare_ok'{} = amqp_channel:call(Ch, #'queue.declare'{}) |
| 150 | + end, |
| 151 | + Nodes), |
| 152 | + Nodes. |
| 153 | + |
| 154 | +suspend_single_queue(Config, Node) -> |
| 155 | + [QPid|_] = [rabbit_amqqueue:pid_of(Q) || Q <- rabbit_ct_broker_helpers:rpc(Config, Node, rabbit_amqqueue, list, []), |
| 156 | + Node == node(rabbit_amqqueue:pid_of(Q))], |
| 157 | + rabbit_ct_broker_helpers:rpc(Config, Node, sys, suspend, [QPid]), |
| 158 | + QPid. |
| 159 | + |
| 160 | +suspend_single_channel(Config, Node) -> |
| 161 | + [CPid|_] = [Pid || Pid <- rabbit_ct_broker_helpers:rpc(Config, Node, rabbit_channel, list_local, []), |
| 162 | + Node == node(Pid)], |
| 163 | + rabbit_ct_broker_helpers:rpc(Config, Node, sys, suspend, [CPid]), |
| 164 | + CPid. |
| 165 | + |
| 166 | +resume_sys_process(Config, Node, Pid) -> |
| 167 | + rabbit_ct_broker_helpers:rpc(Config, Node, sys, resume, [Pid]). |
0 commit comments