Skip to content

Commit

Permalink
Fix set_token_rate to return {period,count} and change EQC test to ma…
Browse files Browse the repository at this point in the history
…tch.
  • Loading branch information
buddhisthead committed Nov 19, 2013
1 parent fdaeeb5 commit 51675e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/riak_core_bg_manager.erl
Expand Up @@ -671,25 +671,24 @@ do_handle_call_exception(Function, Args, State) ->

%% @doc Throws {unregistered, Resource} for unknown Lock.
do_disable_lock(Lock, Kill, State) ->
Info = resource_info(Token, State),
Info = resource_info(Lock, State),
enforce_type_or_throw(Lock, lock, Info),
maybe_honor_limit(Kill, Lock, 0, State),
do_enable_resource(Lock, false, State).

%% @doc Throws unregistered for unknown Token
do_set_token_rate(Token, Rate, State) ->
try
Info = resource_info(Token, State),
Info = #resource_info{type=token, limit=OldRate} = resource_info(Token, State),
enforce_type_or_throw(Token, token, Info),
OldRate = limit(Info),
State2 = update_limit(Token, Rate, Info, State),
schedule_refill_tokens(Token, State2),
%% maybe reschedule blocked callers
State3 = maybe_unblock_blocked(Token, State2),
{reply, OldRate, State3}
catch
{unregistered, Token} ->
{reply, 0, update_limit(Token, Rate, ?DEFAULT_TOKEN_INFO, State)};
{reply, {0, 0}, update_limit(Token, Rate, ?DEFAULT_TOKEN_INFO, State)};
{badtype, _Token}=Error ->
{reply, Error, State}
end.
Expand Down
20 changes: 10 additions & 10 deletions test/bg_manager_eqc.erl
Expand Up @@ -7,8 +7,8 @@

-module(bg_manager_eqc).

-ifdef(TEST).
-ifdef(EQC).
%%-ifdef(TEST).
%% -ifdef(EQC).

-include_lib("eqc/include/eqc.hrl").
-include_lib("eqc/include/eqc_statem.hrl").
Expand Down Expand Up @@ -286,9 +286,7 @@ set_token_rate(Type, Count) ->
set_token_rate_post(S, [Type, _Count], Res) ->
%% check returned value is equal to value we have in state prior to this call
%% since returned value is promised to be previous one that was set
%% eq(Res, mk_token_rate(max_num_tokens(Type, 0, S))).
%% NOTE: workaround for bug, above fails so using this for now
eq(Res, max_num_tokens(Type, 0, S)).
eq(Res, mk_token_rate(max_num_tokens(Type, 0, S))).

%% ------ Grouped operator: token_rate
%% @doc token_rate_command
Expand Down Expand Up @@ -451,8 +449,8 @@ token_count() ->

%% @doc weight/2 - Distribution of calls
weight(_S, set_concurrency_limit) -> 3;
weight(_S, concurrency_limit) -> 0;
weight(_S, concurrency_limit_reached) -> 0;
weight(_S, concurrency_limit) -> 3;
weight(_S, concurrency_limit_reached) -> 3;
weight(_S, start_process) -> 3;
weight(#state{alive=true}, stop_process) -> 5;
weight(#state{alive=false}, stop_process) -> 50;
Expand Down Expand Up @@ -492,6 +490,8 @@ is_alive(#state{alive=Alive}) ->

mk_token_rate({unregistered, _}=Unreg) ->
Unreg;
mk_token_rate(0) ->
{0, 0};
mk_token_rate(Count) ->
%% 4294967295 is erlang:send_after max which is used for token refilling
{4294967295 div 1000, Count}.
Expand Down Expand Up @@ -570,7 +570,7 @@ prop_bgmgr() ->
begin
stop_pid(whereis(riak_core_table_manager)),
stop_pid(whereis(riak_core_bg_manager)),
{ok, TableMgr} = riak_core_table_manager:start_link([{background_mgr_table,
{ok, _TableMgr} = riak_core_table_manager:start_link([{background_mgr_table,
[protected, bag, named_table]}]),
{ok, BgMgr} = riak_core_bg_manager:start_link(),
%% unlink bgmgr so we can crash it, unfortunately we won't surface non-intentional
Expand Down Expand Up @@ -643,5 +643,5 @@ prop_bgmgr_parallel() ->
Res == ok))
end))).

-endif.
-endif.
%% -endif.
%% -endif.

0 comments on commit 51675e5

Please sign in to comment.