Skip to content

Commit

Permalink
Support integers in memory relative free disk space limits
Browse files Browse the repository at this point in the history
rabbitmq-server#1194
[#144271963]
  • Loading branch information
dcorbacho committed Apr 25, 2017
1 parent f3346e8 commit 43fe62e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/rabbit_disk_monitor.erl
Expand Up @@ -237,7 +237,7 @@ parse_free_win32(CommandResult) ->
list_to_integer(lists:reverse(Free)).

interpret_limit({mem_relative, Relative})
when is_float(Relative) ->
when is_number(Relative) ->
round(Relative * vm_memory_monitor:get_total_memory());
interpret_limit(Absolute) ->
case rabbit_resource_monitor_misc:parse_information_unit(Absolute) of
Expand Down
21 changes: 16 additions & 5 deletions test/unit_inbroker_parallel_SUITE.erl
Expand Up @@ -1521,15 +1521,26 @@ set_disk_free_limit_command1(_Config) ->
ok = control_action(set_disk_free_limit,
["2000kiB"]),
2048000 = rabbit_disk_monitor:get_disk_free_limit(),

%% Use an integer
ok = control_action(set_disk_free_limit,
["mem_relative", "1.1"]),
ExpectedLimit = 1.1 * vm_memory_monitor:get_total_memory(),
% Total memory is unstable, so checking order
true = ExpectedLimit/rabbit_disk_monitor:get_disk_free_limit() < 1.2,
true = ExpectedLimit/rabbit_disk_monitor:get_disk_free_limit() > 0.98,
["mem_relative", "1"]),
check_limit(1),

%% Use a float
ok = control_action(set_disk_free_limit,
["mem_relative", "1.5"]),
check_limit(1.5),

ok = control_action(set_disk_free_limit, ["50MB"]),
passed.

check_limit(Limit) ->
ExpectedLimit = Limit * vm_memory_monitor:get_total_memory(),
% Total memory is unstable, so checking order
true = ExpectedLimit/rabbit_disk_monitor:get_disk_free_limit() < 1.2,
true = ExpectedLimit/rabbit_disk_monitor:get_disk_free_limit() > 0.98.

%% ---------------------------------------------------------------------------
%% rabbitmqctl helpers.
%% ---------------------------------------------------------------------------
Expand Down

0 comments on commit 43fe62e

Please sign in to comment.