Skip to content

Commit 60dad90

Browse files
Add test case for the clear cache command
1 parent 9b5e256 commit 60dad90

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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(clear_cache_command_SUITE).
9+
10+
-include_lib("stdlib/include/assert.hrl").
11+
12+
-compile(export_all).
13+
14+
-define(CLEAR_CACHE_CMD, 'Elixir.RabbitMQ.CLI.Ctl.Commands.ClearAuthBackendCacheCommand').
15+
16+
all() ->
17+
[
18+
{group, non_parallel_tests},
19+
{group, cluster_size_2}
20+
].
21+
22+
groups() ->
23+
[
24+
{non_parallel_tests, [], [
25+
clear_cache
26+
]},
27+
{cluster_size_2, [], [
28+
clear_cache
29+
]}
30+
].
31+
32+
%% -------------------------------------------------------------------
33+
%% Testsuite setup/teardown.
34+
%% -------------------------------------------------------------------
35+
36+
init_per_suite(Config) ->
37+
rabbit_ct_helpers:log_environment(),
38+
rabbit_ct_helpers:run_setup_steps(Config).
39+
40+
41+
setup_env(Config, Nodename) ->
42+
rpc(Config, Nodename, application, set_env,
43+
[rabbit, auth_backends, [rabbit_auth_backend_cache]]),
44+
Config.
45+
46+
end_per_suite(Config) ->
47+
rabbit_ct_helpers:run_teardown_steps(Config).
48+
49+
init_per_group(cluster_size_2, Config) ->
50+
init_per_multinode_group(cluster_size_2, Config, 2);
51+
init_per_group(Group, Config) ->
52+
init_per_multinode_group(Group, Config, 1).
53+
54+
init_per_multinode_group(_Group, Config, NodeCount) ->
55+
Suffix = rabbit_ct_helpers:testcase_absname(Config, "", "-"),
56+
Config1 = rabbit_ct_helpers:set_config(Config, [
57+
{rmq_nodes_count, NodeCount},
58+
{rmq_nodename_suffix, Suffix}
59+
]),
60+
rabbit_ct_helpers:run_steps(Config1,
61+
rabbit_ct_broker_helpers:setup_steps() ++
62+
rabbit_ct_client_helpers:setup_steps()).
63+
64+
end_per_group(_Group, Config) ->
65+
rabbit_ct_helpers:run_steps(Config,
66+
rabbit_ct_client_helpers:teardown_steps() ++
67+
rabbit_ct_broker_helpers:teardown_steps()).
68+
69+
init_per_testcase(Testcase, Config) ->
70+
rabbit_ct_helpers:testcase_started(Config, Testcase).
71+
72+
end_per_testcase(Testcase, Config) ->
73+
rabbit_ct_helpers:testcase_finished(Config, Testcase).
74+
75+
%% -------------------------------------------------------------------
76+
%% Testcases.
77+
%% -------------------------------------------------------------------
78+
79+
80+
clear_cache(Config) ->
81+
F = user_login_authentication,
82+
A = [<<"guest">>, [{password, <<"guest">>}]],
83+
Nodes = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
84+
[ setup_env(Config, Nodename) || Nodename <- Nodes],
85+
86+
[ ok = ensure_cache_entries(Config, Node, {F, A}) || Node <- Nodes],
87+
?CLEAR_CACHE_CMD:run([], #{node => lists:last(Nodes)}),
88+
[ {error, not_found} = has_cache_entry(Config, Node, {F, A}) || Node <- Nodes].
89+
90+
ensure_cache_entries(Config, Nodename, {F, A}) ->
91+
{ok, AuthRespOk} = rpc(Config, Nodename, rabbit_auth_backend_internal, F, A),
92+
{ok, AuthRespOk} = rpc(Config, Nodename, rabbit_auth_backend_cache, F, A),
93+
ok = has_cache_entry(Config, Nodename, {F, A}).
94+
95+
rpc(Config, N, M, F, A) ->
96+
rabbit_ct_broker_helpers:rpc(Config, N, M, F, A).
97+
98+
has_cache_entry(Config, Node, {F, A}) ->
99+
{ok, AuthCache} = rpc(Config, Node, application, get_env,
100+
[rabbitmq_auth_backend_cache, cache_module]),
101+
case rpc(Config, Node, AuthCache, get, [{F, A}]) of
102+
{ok, _} -> ok;
103+
{error, not_found} = E -> E
104+
end.

0 commit comments

Comments
 (0)