Skip to content

Commit

Permalink
riak_core_vnode_worker_pool to gen_statem (#19)
Browse files Browse the repository at this point in the history
Rewrote gen_fsm_compat -> gen_statem for module riak_core_vnode_worker_pool
  • Loading branch information
Albert Schimpf committed Jul 13, 2021
1 parent 004205d commit b5da965
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 201 deletions.
5 changes: 3 additions & 2 deletions include/riak_core_vnode.hrl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
-type sender_type() :: fsm | server | raw.
-type sender() :: {sender_type(), reference() | tuple(), pid()} |
%% TODO: Double-check that these special cases are kosher
{server, undefined, undefined} | % special case in
% riak_core_vnode_master.erl
{fsm, undefined, pid()} | % what are these special cases and what is the reference used for??
{server, undefined, undefined} | % special case in riak_core_vnode_master.erl
ignore.

-type partition() :: chash:index_as_int().
-type vnode_req() :: term().
-type keyspaces() :: [{partition(), [partition()]}].
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%{cover_enabled, true}.
{erl_opts, [warnings_as_errors,
{erl_opts, [
debug_info]}.
{edoc_opts, [{preprocess, true}]}.
{xref_checks, []}.
Expand Down
5 changes: 1 addition & 4 deletions src/riak_core_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,7 @@ proxy_spawn(Fun) ->


%% @private
make_fold_reqv(v1, FoldFun, Acc0, _Forwardable, _Opts)
when is_function(FoldFun, 3) ->
#riak_core_fold_req_v1{foldfun=FoldFun, acc0=Acc0};
make_fold_reqv(v2, FoldFun, Acc0, Forwardable, Opts)
make_fold_reqv(_, FoldFun, Acc0, Forwardable, Opts)
when is_function(FoldFun, 3)
andalso (Forwardable == true orelse Forwardable == false)
andalso is_list(Opts) ->
Expand Down
13 changes: 6 additions & 7 deletions src/riak_core_vnode.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1095,30 +1095,29 @@ current_state(Pid) ->
gen_fsm:sync_send_all_state_event(Pid, current_state).

pool_death_test() ->
%% expect error log
error_logger:tty(false),
meck:unload(),
meck:new(test_vnode, [non_strict, no_link]),
meck:expect(test_vnode, init, fun(_) -> {ok, [], [{pool, test_pool_mod, 1, []}]} end),
meck:expect(test_vnode, terminate, fun(_, _) -> normal end),
meck:new(test_pool_mod, [non_strict, no_link]),
meck:expect(test_pool_mod, init_worker, fun(_, _, _) -> {ok, []} end),

%% expect error log
error_logger:tty(false),

{ok, Pid} = ?MODULE:test_link(test_vnode, 0),
{_, StateData1} = ?MODULE:current_state(Pid),
{ok, Pid} = riak_core_vnode:test_link(test_vnode, 0),
{_, StateData1} = riak_core_vnode:current_state(Pid),
PoolPid1 = StateData1#state.pool_pid,
exit(PoolPid1, kill),
wait_for_process_death(PoolPid1),
?assertNot(is_process_alive(PoolPid1)),

wait_for_state_update(StateData1, Pid),
{_, StateData2} = ?MODULE:current_state(Pid),
{_, StateData2} = riak_core_vnode:current_state(Pid),
PoolPid2 = StateData2#state.pool_pid,
?assertNot(PoolPid2 =:= undefined),
exit(Pid, normal),
wait_for_process_death(Pid),

error_logger:tty(false),
meck:validate(test_pool_mod),
meck:validate(test_vnode).

Expand Down
Loading

0 comments on commit b5da965

Please sign in to comment.