Skip to content

Commit

Permalink
Remove non-named-maps change_rate helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Jul 1, 2024
1 parent 2ae0719 commit e09fdf1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
16 changes: 1 addition & 15 deletions src/throttle/amoc_throttle.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
-export([start/2, stop/1,
send/2, send/3, wait/1,
run/2, pause/1, resume/1, unlock/1,
change_rate/2, change_rate/3,
change_rate_gradually/2, change_rate_gradually/6]).
change_rate/2, change_rate_gradually/2]).

-type name() :: atom().
%% Atom representing the name of the throttle.
Expand Down Expand Up @@ -87,11 +86,6 @@ unlock(Name) ->
change_rate(Name, #{rate := Rate, interval := Interval}) ->
amoc_throttle_controller:change_rate(Name, Rate, Interval).

%% @see change_rate/2
-spec change_rate(name(), rate(), interval()) -> ok | {error, any()}.
change_rate(Name, Rate, Interval) ->
amoc_throttle_controller:change_rate(Name, Rate, Interval).

%% @doc Allows to set a plan of gradual rate changes for a given `Name'.
%%
%% `Rate' will be changed from `FromRate' to `ToRate' in a series of consecutive steps.
Expand All @@ -107,14 +101,6 @@ change_rate(Name, Rate, Interval) ->
change_rate_gradually(Name, Config) ->
amoc_throttle_controller:change_rate_gradually(Name, Config).

%% @see change_rate_gradually/2
-spec change_rate_gradually(name(), rate(), rate(), interval(), pos_integer(), pos_integer()) ->
ok | {error, any()}.
change_rate_gradually(Name, FromRate, ToRate, RateInterval, StepInterval, StepCount) ->
Config = #{from_rate => FromRate, to_rate => ToRate, interval => RateInterval,
step_interval => StepInterval, step_count => StepCount},
amoc_throttle_controller:change_rate_gradually(Name, Config).

%% @doc Executes a given function `Fn' when it does not exceed the rate for `Name'.
%%
%% `Fn' is executed in the context of a new process spawned on the same node on which
Expand Down
42 changes: 20 additions & 22 deletions test/throttle_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ groups() ->
start_and_stop,
change_rate,
change_rate_gradually,
change_rate_gradually_descriptive,
change_rate_gradually_verify_descriptions,
just_wait,
wait_for_process_to_die_sends_a_kill,
Expand Down Expand Up @@ -146,34 +145,33 @@ start_and_stop(_) ->

change_rate(_) ->
?assertMatch({error, {no_throttle_by_name, ?FUNCTION_NAME}},
amoc_throttle:change_rate(?FUNCTION_NAME, 100, ?DEFAULT_INTERVAL)),
amoc_throttle:change_rate(?FUNCTION_NAME,
#{rate => 100, interval => ?DEFAULT_INTERVAL})),
?assertMatch({ok, started}, amoc_throttle:start(?FUNCTION_NAME, 100)),
?assertMatch(ok, amoc_throttle:change_rate(?FUNCTION_NAME, 100, ?DEFAULT_INTERVAL)),
?assertMatch(ok, amoc_throttle:change_rate(?FUNCTION_NAME, 100, ?DEFAULT_INTERVAL + 1)),
E1 = #{rate => 100, interval => ?DEFAULT_INTERVAL + 2},
?assertMatch(ok, amoc_throttle:change_rate(?FUNCTION_NAME, E1)).
E1 = #{rate => 100, interval => ?DEFAULT_INTERVAL},
?assertMatch(ok, amoc_throttle:change_rate(?FUNCTION_NAME, E1)),
E2 = #{rate => 100, interval => ?DEFAULT_INTERVAL + 1},
?assertMatch(ok, amoc_throttle:change_rate(?FUNCTION_NAME, E2)),
E3 = #{rate => 100, interval => ?DEFAULT_INTERVAL + 2},
?assertMatch(ok, amoc_throttle:change_rate(?FUNCTION_NAME, E3)).

change_rate_gradually(_) ->
C1 = #{from_rate => 100, to_rate => 200, interval => 1,
step_interval => 1, step_count => 1},
?assertMatch({error, {no_throttle_by_name, ?FUNCTION_NAME}},
amoc_throttle:change_rate_gradually(?FUNCTION_NAME, 100, 200, 1, 1, 1)),
amoc_throttle:change_rate_gradually(?FUNCTION_NAME, C1)),
?assertMatch({ok, started}, amoc_throttle:start(?FUNCTION_NAME, 100)),
?assertMatch(ok, amoc_throttle:change_rate_gradually(?FUNCTION_NAME, 10, 3000, 1, 100, 300)),

C2 = #{from_rate => 10, to_rate => 3000, interval => 1,
step_interval => 100, step_count => 300},
?assertMatch(ok, amoc_throttle:change_rate_gradually(?FUNCTION_NAME, C2)),
%% We cannot change rate while a current gradual change is already running.
C3 = #{from_rate => 50, to_rate => 200, interval => 1,
step_interval => 1, step_count => 1},
?assertMatch({error, cannot_change_rate},
amoc_throttle:change_rate_gradually(?FUNCTION_NAME, 50, 200, 1, 1, 1)),
?assertMatch({error, cannot_change_rate},
amoc_throttle:change_rate(?FUNCTION_NAME, 100, ?DEFAULT_INTERVAL + 1)).

change_rate_gradually_descriptive(_) ->
?assertMatch({ok, started}, amoc_throttle:start(?FUNCTION_NAME, 100)),
%% Bad description fails to change rate
D1 = #{from_rate => 50, to_rate => 200, interval => 1,
step_interval => 1, step_count => 1, step_size => 1},
?assertMatch({error, _}, amoc_throttle:change_rate_gradually(?FUNCTION_NAME, D1)),
%% Good description changes rate successfully
Description = #{from_rate => 10, to_rate => 3000, interval => 1,
step_interval => 100, step_count => 300, step_size => 9},
?assertMatch(ok, amoc_throttle:change_rate_gradually(?FUNCTION_NAME, Description)).
amoc_throttle:change_rate_gradually(?FUNCTION_NAME, C3)),
E1 = #{rate => 100, interval => ?DEFAULT_INTERVAL + 1},
?assertMatch({error, cannot_change_rate}, amoc_throttle:change_rate(?FUNCTION_NAME, E1)).

%% Bad description also fails
change_rate_gradually_verify_descriptions(_) ->
Expand Down

0 comments on commit e09fdf1

Please sign in to comment.