2020-07-10 21:31:17 +08:00
|
|
|
%% This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
%% License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
2020-03-31 02:16:38 +08:00
|
|
|
%%
|
2024-02-06 00:53:36 +08:00
|
|
|
%% Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
|
2020-03-31 02:16:38 +08:00
|
|
|
%%
|
|
|
|
|
|
|
|
-module(unit_disk_monitor_SUITE).
|
|
|
|
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
|
|
|
|
-compile(export_all).
|
|
|
|
|
|
|
|
-define(TIMEOUT, 30000).
|
|
|
|
|
|
|
|
all() ->
|
|
|
|
[
|
2020-03-31 03:19:02 +08:00
|
|
|
{group, sequential_tests}
|
2020-03-31 02:16:38 +08:00
|
|
|
].
|
|
|
|
|
|
|
|
groups() ->
|
|
|
|
[
|
2020-03-31 03:19:02 +08:00
|
|
|
{sequential_tests, [], [
|
|
|
|
set_disk_free_limit_command
|
2020-03-31 02:16:38 +08:00
|
|
|
]}
|
|
|
|
].
|
|
|
|
|
|
|
|
%% -------------------------------------------------------------------
|
2020-03-31 03:19:02 +08:00
|
|
|
%% Testsuite setup/teardown
|
2020-03-31 02:16:38 +08:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
|
|
|
init_per_suite(Config) ->
|
|
|
|
rabbit_ct_helpers:log_environment(),
|
|
|
|
rabbit_ct_helpers:run_setup_steps(Config).
|
|
|
|
|
|
|
|
end_per_suite(Config) ->
|
|
|
|
rabbit_ct_helpers:run_teardown_steps(Config).
|
|
|
|
|
|
|
|
init_per_group(Group, Config) ->
|
|
|
|
Config1 = rabbit_ct_helpers:set_config(Config, [
|
|
|
|
{rmq_nodename_suffix, Group},
|
2020-03-31 03:19:02 +08:00
|
|
|
{rmq_nodes_count, 1}
|
2020-03-31 02:16:38 +08:00
|
|
|
]),
|
|
|
|
rabbit_ct_helpers:run_steps(Config1,
|
|
|
|
rabbit_ct_broker_helpers:setup_steps() ++
|
|
|
|
rabbit_ct_client_helpers:setup_steps()).
|
|
|
|
|
|
|
|
end_per_group(_Group, Config) ->
|
|
|
|
rabbit_ct_helpers:run_steps(Config,
|
|
|
|
rabbit_ct_client_helpers:teardown_steps() ++
|
|
|
|
rabbit_ct_broker_helpers:teardown_steps()).
|
|
|
|
|
|
|
|
init_per_testcase(Testcase, Config) ->
|
|
|
|
rabbit_ct_helpers:testcase_started(Config, Testcase).
|
|
|
|
|
|
|
|
end_per_testcase(Testcase, Config) ->
|
|
|
|
rabbit_ct_helpers:testcase_finished(Config, Testcase).
|
|
|
|
|
|
|
|
|
2020-03-31 03:19:02 +08:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%% Test cases
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
|
|
|
set_disk_free_limit_command(Config) ->
|
|
|
|
passed = rabbit_ct_broker_helpers:rpc(Config, 0,
|
|
|
|
?MODULE, set_disk_free_limit_command1, [Config]).
|
|
|
|
|
|
|
|
set_disk_free_limit_command1(_Config) ->
|
2021-12-20 23:13:35 +08:00
|
|
|
F = fun () ->
|
|
|
|
DiskFree = rabbit_disk_monitor:get_disk_free(),
|
2022-09-08 00:46:51 +08:00
|
|
|
DiskFree =/= 'NaN'
|
2021-12-20 23:13:35 +08:00
|
|
|
end,
|
|
|
|
rabbit_ct_helpers:await_condition(F),
|
|
|
|
|
2020-03-31 03:19:02 +08:00
|
|
|
%% Use an integer
|
|
|
|
rabbit_disk_monitor:set_disk_free_limit({mem_relative, 1}),
|
|
|
|
disk_free_limit_to_total_memory_ratio_is(1),
|
|
|
|
|
|
|
|
%% Use a float
|
|
|
|
rabbit_disk_monitor:set_disk_free_limit({mem_relative, 1.5}),
|
|
|
|
disk_free_limit_to_total_memory_ratio_is(1.5),
|
|
|
|
|
2020-03-31 04:10:31 +08:00
|
|
|
%% use an absolute value
|
|
|
|
rabbit_disk_monitor:set_disk_free_limit("70MiB"),
|
|
|
|
?assertEqual(73400320, rabbit_disk_monitor:get_disk_free_limit()),
|
|
|
|
|
2020-03-31 03:19:02 +08:00
|
|
|
rabbit_disk_monitor:set_disk_free_limit("50MB"),
|
2020-03-31 04:10:31 +08:00
|
|
|
?assertEqual(50 * 1000 * 1000, rabbit_disk_monitor:get_disk_free_limit()),
|
2020-03-31 03:19:02 +08:00
|
|
|
passed.
|
|
|
|
|
|
|
|
disk_free_limit_to_total_memory_ratio_is(MemRatio) ->
|
2021-12-20 23:13:35 +08:00
|
|
|
DiskFreeLimit = rabbit_disk_monitor:get_disk_free_limit(),
|
2020-03-31 03:19:02 +08:00
|
|
|
ExpectedLimit = MemRatio * vm_memory_monitor:get_total_memory(),
|
|
|
|
% Total memory is unstable, so checking order
|
2021-12-20 23:13:35 +08:00
|
|
|
true = ExpectedLimit/DiskFreeLimit < 1.2,
|
|
|
|
true = ExpectedLimit/DiskFreeLimit > 0.98.
|