Skip to content

Commit

Permalink
Add proper test and docs for format_status/2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Brujo Benavides committed Jul 17, 2018
1 parent 5063f06 commit 9ce28d5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/wpool_process_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
, cast/1
, call/1
, continue/1
, format_status/1
, no_format_status/1
, stop/1
]).
Expand Down Expand Up @@ -169,6 +170,17 @@ continue(_Config) ->

{comment, []}.

-spec format_status(config()) -> {comment, []}.
format_status(_Config) ->
%% echo_server implements format_status/2
{ok, Pid} = wpool_process:start_link(?MODULE, echo_server, {ok, state}, []),
%% therefore it returns {formatted_state, State} as its status and we just pass it through
{status, Pid, {module, gen_server}, SItems} = sys:get_status(Pid),
[state] = [S || SItemList = [_|_] <- SItems, {formatted_state, S} <- SItemList],
%% this code is actually what we use to retrieve the state in other tests
state = get_state(Pid),
{comment, []}.

-spec no_format_status(config()) -> {comment, []}.
no_format_status(_Config) ->
%% crashy_server doesn't implement format_status/2
Expand Down Expand Up @@ -306,6 +318,12 @@ complete_coverage(_Config) ->

{comment, []}.


%% @doc We can use this function in tests since echo_server implements format_status/2
%% by returning the state as a tuple {formatted_state, S}.
%% We can safely grab it from the result of sys:get_status/1
%% @see gen_server:format_status/2
%% @see sys:get_status/2
get_state(Atom) when is_atom(Atom) ->
get_state(whereis(Atom));
get_state(Pid) ->
Expand Down

0 comments on commit 9ce28d5

Please sign in to comment.