Skip to content

Commit

Permalink
Delete vhost in a separate process
Browse files Browse the repository at this point in the history
  • Loading branch information
anhanhnguyen committed Feb 19, 2024
1 parent 01e4583 commit 32db751
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deps/rabbitmq_management/src/rabbit_mgmt_wm_vhost.erl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ accept_content(ReqData0, Context = #context{user = #user{username = Username}})
delete_resource(ReqData, Context = #context{user = #user{username = Username}}) ->
VHost = id(ReqData),
try
rabbit_vhost:delete(VHost, Username)
spawn_link(rabbit_vhost, delete, [VHost, Username])
catch _:{error, {no_such_vhost, _}} ->
ok
end,
Expand Down
38 changes: 38 additions & 0 deletions deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ all_tests() -> [
vhosts_test,
vhosts_description_test,
vhosts_trace_test,
large_vhosts_delete_test,
users_test,
users_legacy_administrator_test,
adding_a_user_with_password_test,
Expand Down Expand Up @@ -237,6 +238,13 @@ init_per_testcase(queues_detailed_test, Config) ->
true -> Config;
false -> {skip, "The detailed queues endpoint is not available."}
end;
init_per_testcase(Testcase = large_vhosts_delete_test, Config) ->
Timeout = [{idle_timeout, 500}, {inactivity_timeout, 500}],
rabbit_ct_broker_helpers:rpc_all(Config,
application,
set_env,
[rabbitmq_management, tcp_config, [{cowboy_opts, Timeout}]]),
rabbit_ct_helpers:testcase_started(Config, Testcase);
init_per_testcase(Testcase, Config) ->
rabbit_ct_broker_helpers:close_all_connections(Config, 0, <<"rabbit_mgmt_SUITE:init_per_testcase">>),
rabbit_ct_helpers:testcase_started(Config, Testcase).
Expand Down Expand Up @@ -309,6 +317,13 @@ end_per_testcase0(Testcase, Config)
clear_injected_test_feature_flags,
[]),
Config;
end_per_testcase0(large_vhosts_delete_test, Config) ->
rabbit_ct_broker_helpers:rpc(Config,
0,
application,
unset_env,
[rabbitmq_management, tcp_config]),
Config;
end_per_testcase0(_, Config) -> Config.

%% -------------------------------------------------------------------
Expand Down Expand Up @@ -510,6 +525,29 @@ vhosts_trace_test(Config) ->

passed.

large_vhosts_delete_test(Config) ->
http_put(Config, "/vhosts/myvhost", none, {group, '2xx'}),

{ok, Conn} =
amqp_connection:start(#amqp_params_direct{node =
rabbit_ct_broker_helpers:get_node_config(Config,
0,
nodename),
virtual_host = <<"myvhost">>}),
{ok, Ch} = amqp_connection:open_channel(Conn),
[amqp_channel:cast(Ch, #'queue.declare'{queue = integer_to_binary(Q), durable = true})
|| Q <- lists:seq(0, 10000)],
amqp_channel:close(Ch),
close_connection(Conn),

http_delete(Config, "/vhosts/myvhost", {group, '2xx'}),

timer:sleep(5000),
http_put(Config, "/vhosts/myvhost", none, {group, '2xx'}),
http_get(Config, "/aliveness-test/myvhost", ?OK),

passed.

users_test(Config) ->
assert_item(#{name => <<"guest">>, tags => [<<"administrator">>]},
http_get(Config, "/whoami")),
Expand Down

0 comments on commit 32db751

Please sign in to comment.