|
| 1 | +%% This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +%% License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +%% file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | +%% |
| 5 | +%% Copyright (c) 2023 VMware, Inc. or its affiliates. All rights reserved. |
| 6 | +%% |
| 7 | + |
| 8 | +-module(rabbitmq_4_0_deprecations_SUITE). |
| 9 | + |
| 10 | +-include_lib("eunit/include/eunit.hrl"). |
| 11 | +-include_lib("common_test/include/ct.hrl"). |
| 12 | + |
| 13 | +-include_lib("amqp_client/include/amqp_client.hrl"). |
| 14 | + |
| 15 | +-export([suite/0, |
| 16 | + all/0, |
| 17 | + groups/0, |
| 18 | + init_per_suite/1, |
| 19 | + end_per_suite/1, |
| 20 | + init_per_group/2, |
| 21 | + end_per_group/2, |
| 22 | + init_per_testcase/2, |
| 23 | + end_per_testcase/2, |
| 24 | + |
| 25 | + when_global_qos_is_permitted_by_default/1, |
| 26 | + when_global_qos_is_not_permitted_from_conf/1 |
| 27 | + ]). |
| 28 | + |
| 29 | +suite() -> |
| 30 | + [{timetrap, {minutes, 5}}]. |
| 31 | + |
| 32 | +all() -> |
| 33 | + [ |
| 34 | + {group, global_qos} |
| 35 | + ]. |
| 36 | + |
| 37 | +groups() -> |
| 38 | + [ |
| 39 | + {global_qos, [], |
| 40 | + [when_global_qos_is_permitted_by_default, |
| 41 | + when_global_qos_is_not_permitted_from_conf]} |
| 42 | + ]. |
| 43 | + |
| 44 | +%% ------------------------------------------------------------------- |
| 45 | +%% Testsuite setup/teardown. |
| 46 | +%% ------------------------------------------------------------------- |
| 47 | + |
| 48 | +init_per_suite(Config) -> |
| 49 | + rabbit_ct_helpers:log_environment(), |
| 50 | + logger:set_primary_config(level, debug), |
| 51 | + rabbit_ct_helpers:run_setup_steps( |
| 52 | + Config, |
| 53 | + [fun rabbit_ct_helpers:redirect_logger_to_ct_logs/1]). |
| 54 | + |
| 55 | +end_per_suite(Config) -> |
| 56 | + Config. |
| 57 | + |
| 58 | +init_per_group(global_qos, Config) -> |
| 59 | + rabbit_ct_helpers:set_config(Config, {rmq_nodes_count, 1}); |
| 60 | +init_per_group(_Group, Config) -> |
| 61 | + Config. |
| 62 | + |
| 63 | +end_per_group(_Group, Config) -> |
| 64 | + Config. |
| 65 | + |
| 66 | +init_per_testcase( |
| 67 | + when_global_qos_is_not_permitted_from_conf = Testcase, Config) -> |
| 68 | + Config1 = rabbit_ct_helpers:merge_app_env( |
| 69 | + Config, |
| 70 | + {rabbit, |
| 71 | + [{permit_deprecated_features, #{global_qos => false}}]}), |
| 72 | + init_per_testcase1(Testcase, Config1); |
| 73 | +init_per_testcase(Testcase, Config) -> |
| 74 | + init_per_testcase1(Testcase, Config). |
| 75 | + |
| 76 | +init_per_testcase1(Testcase, Config) -> |
| 77 | + rabbit_ct_helpers:testcase_started(Config, Testcase), |
| 78 | + ClusterSize = ?config(rmq_nodes_count, Config), |
| 79 | + TestNumber = rabbit_ct_helpers:testcase_number(Config, ?MODULE, Testcase), |
| 80 | + Config1 = rabbit_ct_helpers:set_config(Config, [ |
| 81 | + {rmq_nodename_suffix, Testcase}, |
| 82 | + {tcp_ports_base, {skip_n_nodes, TestNumber * ClusterSize}}, |
| 83 | + {keep_pid_file_on_exit, true} |
| 84 | + ]), |
| 85 | + rabbit_ct_helpers:run_steps(Config1, |
| 86 | + rabbit_ct_broker_helpers:setup_steps() ++ |
| 87 | + rabbit_ct_client_helpers:setup_steps()). |
| 88 | + |
| 89 | +end_per_testcase(Testcase, Config) -> |
| 90 | + Config1 = rabbit_ct_helpers:run_steps(Config, |
| 91 | + rabbit_ct_client_helpers:teardown_steps() ++ |
| 92 | + rabbit_ct_broker_helpers:teardown_steps()), |
| 93 | + rabbit_ct_helpers:testcase_finished(Config1, Testcase). |
| 94 | + |
| 95 | +%% ------------------------------------------------------------------- |
| 96 | +%% Global QoS. |
| 97 | +%% ------------------------------------------------------------------- |
| 98 | + |
| 99 | +when_global_qos_is_permitted_by_default(Config) -> |
| 100 | + [NodeA] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename), |
| 101 | + |
| 102 | + ExistingServerChs = list_server_channels(Config, NodeA), |
| 103 | + ClientCh = rabbit_ct_client_helpers:open_channel(Config, NodeA), |
| 104 | + [ServerCh] = list_server_channels(Config, NodeA) -- ExistingServerChs, |
| 105 | + |
| 106 | + ?assertNot(is_prefetch_limited(ServerCh)), |
| 107 | + |
| 108 | + %% It's possible to request global QoS and it is accepted by the server. |
| 109 | + ?assertMatch( |
| 110 | + #'basic.qos_ok'{}, |
| 111 | + amqp_channel:call( |
| 112 | + ClientCh, |
| 113 | + #'basic.qos'{global = true, prefetch_count = 10})), |
| 114 | + ?assert(is_prefetch_limited(ServerCh)), |
| 115 | + |
| 116 | + ?assert( |
| 117 | + log_file_contains_message( |
| 118 | + Config, NodeA, |
| 119 | + ["Deprecated features: `global_qos`: Feature `global_qos` is deprecated", |
| 120 | + "By default, this feature can still be used for now."])). |
| 121 | + |
| 122 | +when_global_qos_is_not_permitted_from_conf(Config) -> |
| 123 | + [NodeA] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename), |
| 124 | + |
| 125 | + ExistingServerChs = list_server_channels(Config, NodeA), |
| 126 | + ClientCh = rabbit_ct_client_helpers:open_channel(Config, NodeA), |
| 127 | + [ServerCh] = list_server_channels(Config, NodeA) -- ExistingServerChs, |
| 128 | + |
| 129 | + ?assertNot(is_prefetch_limited(ServerCh)), |
| 130 | + |
| 131 | + %% It's possible to request global QoS but it is ignored by the server. |
| 132 | + ?assertMatch( |
| 133 | + #'basic.qos_ok'{}, |
| 134 | + amqp_channel:call( |
| 135 | + ClientCh, |
| 136 | + #'basic.qos'{global = true, prefetch_count = 10})), |
| 137 | + ?assertNot(is_prefetch_limited(ServerCh)), |
| 138 | + |
| 139 | + ?assert( |
| 140 | + log_file_contains_message( |
| 141 | + Config, NodeA, |
| 142 | + ["Deprecated features: `global_qos`: Feature `global_qos` is deprecated", |
| 143 | + "Its use is not permitted per the configuration"])). |
| 144 | + |
| 145 | +list_server_channels(Config, Node) -> |
| 146 | + rabbit_ct_broker_helpers:rpc(Config, Node, rabbit_channel, list, []). |
| 147 | + |
| 148 | +is_prefetch_limited(ServerCh) -> |
| 149 | + GenServer2State = sys:get_state(ServerCh), |
| 150 | + ChState = element(4, GenServer2State), |
| 151 | + ct:pal("Server channel (~p) state: ~p", [ServerCh, ChState]), |
| 152 | + LimiterState = element(3, ChState), |
| 153 | + element(3, LimiterState). |
| 154 | + |
| 155 | +%% ------------------------------------------------------------------- |
| 156 | +%% Helpers. |
| 157 | +%% ------------------------------------------------------------------- |
| 158 | + |
| 159 | +log_file_contains_message(Config, Node, Messages) -> |
| 160 | + _ = catch rabbit_ct_broker_helpers:rpc( |
| 161 | + Config, Node, rabbit_logger_std_h, filesync, [rmq_1_file_1]), |
| 162 | + _ = catch rabbit_ct_broker_helpers:rpc( |
| 163 | + Config, Node, rabbit_logger_std_h, filesync, [rmq_2_file_1]), |
| 164 | + LogLocations = rabbit_ct_broker_helpers:rpc( |
| 165 | + Config, Node, rabbit, log_locations, []), |
| 166 | + LogFiles = [LogLocation || |
| 167 | + LogLocation <- LogLocations, |
| 168 | + filelib:is_regular(LogLocation)], |
| 169 | + ?assertNotEqual([], LogFiles), |
| 170 | + lists:any( |
| 171 | + fun(LogFile) -> |
| 172 | + {ok, Content} = file:read_file(LogFile), |
| 173 | + find_messages(Content, Messages) |
| 174 | + end, LogFiles). |
| 175 | + |
| 176 | +find_messages(Content, [Message | Rest]) -> |
| 177 | + case string:find(Content, Message) of |
| 178 | + nomatch -> false; |
| 179 | + Remaining -> find_messages(Remaining, Rest) |
| 180 | + end; |
| 181 | +find_messages(_Content, []) -> |
| 182 | + true. |
0 commit comments