|
| 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 | +when_global_qos_is_not_permitted_from_conf(Config) -> |
| 117 | + [NodeA] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename), |
| 118 | + |
| 119 | + ExistingServerChs = list_server_channels(Config, NodeA), |
| 120 | + ClientCh = rabbit_ct_client_helpers:open_channel(Config, NodeA), |
| 121 | + [ServerCh] = list_server_channels(Config, NodeA) -- ExistingServerChs, |
| 122 | + |
| 123 | + ?assertNot(is_prefetch_limited(ServerCh)), |
| 124 | + |
| 125 | + %% It's possible to request global QoS but it is ignored by the server. |
| 126 | + ?assertMatch( |
| 127 | + #'basic.qos_ok'{}, |
| 128 | + amqp_channel:call( |
| 129 | + ClientCh, |
| 130 | + #'basic.qos'{global = true, prefetch_count = 10})), |
| 131 | + ?assertNot(is_prefetch_limited(ServerCh)). |
| 132 | + |
| 133 | +list_server_channels(Config, Node) -> |
| 134 | + rabbit_ct_broker_helpers:rpc(Config, Node, rabbit_channel, list, []). |
| 135 | + |
| 136 | +is_prefetch_limited(ServerCh) -> |
| 137 | + GenServer2State = sys:get_state(ServerCh), |
| 138 | + ChState = element(4, GenServer2State), |
| 139 | + ct:pal("Server channel (~p) state: ~p", [ServerCh, ChState]), |
| 140 | + LimiterState = element(3, ChState), |
| 141 | + element(3, LimiterState). |
0 commit comments