|
| 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) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. |
| 6 | +%% |
| 7 | + |
| 8 | +-module(default_queue_type_prop_SUITE). |
| 9 | + |
| 10 | +-include_lib("common_test/include/ct.hrl"). |
| 11 | +-include_lib("proper/include/proper.hrl"). |
| 12 | + |
| 13 | +-import(rabbit_ct_broker_helpers, [rpc/5]). |
| 14 | + |
| 15 | +-compile(nowarn_export_all). |
| 16 | +-compile(export_all). |
| 17 | + |
| 18 | +all() -> |
| 19 | + [ |
| 20 | + prop_inject_dqt_output_invariants, |
| 21 | + prop_inject_dqt_preserves_valid_types |
| 22 | + ]. |
| 23 | + |
| 24 | +%% ------------------------------------------------------------------- |
| 25 | +%% Test suite setup/teardown. |
| 26 | +%% ------------------------------------------------------------------- |
| 27 | + |
| 28 | +init_per_suite(Config) -> |
| 29 | + rabbit_ct_helpers:log_environment(), |
| 30 | + rabbit_ct_helpers:run_setup_steps(Config). |
| 31 | + |
| 32 | +end_per_suite(Config) -> |
| 33 | + rabbit_ct_helpers:run_teardown_steps(Config). |
| 34 | + |
| 35 | +init_per_group(Group, Config) -> |
| 36 | + Config1 = rabbit_ct_helpers:set_config(Config, [ |
| 37 | + {rmq_nodename_suffix, Group}, |
| 38 | + {rmq_nodes_count, 1} |
| 39 | + ]), |
| 40 | + rabbit_ct_helpers:run_steps(Config1, |
| 41 | + rabbit_ct_broker_helpers:setup_steps() ++ |
| 42 | + rabbit_ct_client_helpers:setup_steps()). |
| 43 | + |
| 44 | +end_per_group(_Group, Config) -> |
| 45 | + rabbit_ct_helpers:run_steps(Config, |
| 46 | + rabbit_ct_client_helpers:teardown_steps() ++ |
| 47 | + rabbit_ct_broker_helpers:teardown_steps()). |
| 48 | + |
| 49 | +init_per_testcase(Testcase, Config) -> |
| 50 | + Config1 = rabbit_ct_helpers:set_config(Config, [ |
| 51 | + {rmq_nodename_suffix, Testcase}, |
| 52 | + {rmq_nodes_count, 1} |
| 53 | + ]), |
| 54 | + Config2 = rabbit_ct_helpers:run_steps(Config1, |
| 55 | + rabbit_ct_broker_helpers:setup_steps() ++ |
| 56 | + rabbit_ct_client_helpers:setup_steps()), |
| 57 | + rabbit_ct_helpers:testcase_started(Config2, Testcase). |
| 58 | + |
| 59 | +end_per_testcase(Testcase, Config) -> |
| 60 | + Config1 = rabbit_ct_helpers:run_steps(Config, |
| 61 | + rabbit_ct_client_helpers:teardown_steps() ++ |
| 62 | + rabbit_ct_broker_helpers:teardown_steps()), |
| 63 | + rabbit_ct_helpers:testcase_finished(Config1, Testcase). |
| 64 | + |
| 65 | +%% ------------------------------------------------------------------- |
| 66 | +%% Property-based Tests |
| 67 | +%% ------------------------------------------------------------------- |
| 68 | + |
| 69 | +%% Property: inject_dqt always produces valid output regardless of input DQT value |
| 70 | +prop_inject_dqt_output_invariants(Config) -> |
| 71 | + Property = fun() -> prop_output_invariants(Config) end, |
| 72 | + rabbit_ct_proper_helpers:run_proper(Property, [], 100). |
| 73 | + |
| 74 | +prop_output_invariants(Config) -> |
| 75 | + ?FORALL({Name, DQT, ExtraMetaKeys}, |
| 76 | + {vhost_name_gen(), dqt_gen(), list(atom())}, |
| 77 | + begin |
| 78 | + ExtraMeta = maps:from_list([{K, K} || K <- ExtraMetaKeys]), |
| 79 | + Input = case DQT of |
| 80 | + none -> #{name => Name, metadata => ExtraMeta}; |
| 81 | + Val -> #{name => Name, default_queue_type => Val, metadata => ExtraMeta} |
| 82 | + end, |
| 83 | + Result = rpc(Config, 0, rabbit_queue_type, inject_dqt, [Input]), |
| 84 | + |
| 85 | + maps:is_key(default_queue_type, Result) andalso |
| 86 | + begin |
| 87 | + Meta = maps:get(metadata, Result, #{}), |
| 88 | + maps:is_key(default_queue_type, Meta) andalso |
| 89 | + lists:all(fun(K) -> maps:is_key(K, Meta) end, ExtraMetaKeys) |
| 90 | + end |
| 91 | + end). |
| 92 | + |
| 93 | +%% Property: valid queue types are preserved, invalid ones fall back to default |
| 94 | +prop_inject_dqt_preserves_valid_types(Config) -> |
| 95 | + Property = fun() -> prop_preserves_valid_types(Config) end, |
| 96 | + rabbit_ct_proper_helpers:run_proper(Property, [], 100). |
| 97 | + |
| 98 | +prop_preserves_valid_types(Config) -> |
| 99 | + Default = rpc(Config, 0, rabbit_queue_type, default_alias, []), |
| 100 | + ?FORALL(DQT, dqt_gen(), |
| 101 | + begin |
| 102 | + Input = case DQT of |
| 103 | + none -> #{name => <<"/">>}; |
| 104 | + Val -> #{name => <<"/">>, default_queue_type => Val} |
| 105 | + end, |
| 106 | + #{default_queue_type := ResultDQT} = |
| 107 | + rpc(Config, 0, rabbit_queue_type, inject_dqt, [Input]), |
| 108 | + |
| 109 | + case DQT of |
| 110 | + none -> ResultDQT =:= Default; |
| 111 | + undefined -> ResultDQT =:= Default; |
| 112 | + <<"undefined">> -> ResultDQT =:= Default; |
| 113 | + "undefined" -> ResultDQT =:= Default; |
| 114 | + <<"classic">> -> ResultDQT =:= <<"classic">>; |
| 115 | + <<"quorum">> -> ResultDQT =:= <<"quorum">>; |
| 116 | + <<"stream">> -> ResultDQT =:= <<"stream">> |
| 117 | + end |
| 118 | + end). |
| 119 | + |
| 120 | +%% ------------------------------------------------------------------- |
| 121 | +%% Generators |
| 122 | +%% ------------------------------------------------------------------- |
| 123 | + |
| 124 | +vhost_name_gen() -> |
| 125 | + ?LET(Name, non_empty(binary()), <<"/", Name/binary>>). |
| 126 | + |
| 127 | +dqt_gen() -> |
| 128 | + oneof([ |
| 129 | + none, |
| 130 | + undefined, |
| 131 | + <<"undefined">>, |
| 132 | + "undefined", |
| 133 | + <<"classic">>, |
| 134 | + <<"quorum">>, |
| 135 | + <<"stream">> |
| 136 | + ]). |
0 commit comments