Skip to content

Commit

Permalink
test: unstick prim_inet for meck
Browse files Browse the repository at this point in the history
  • Loading branch information
zmstone committed Nov 12, 2024
1 parent 10475ca commit 69ffe5a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 41 deletions.
17 changes: 3 additions & 14 deletions src/esockd_acceptor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ handle_event(internal, accept_and_close, suspending, State = #state{lsock = LSoc
case async_accept(suspending, LSock) of
{ok, Ref} ->
{keep_state, State#state{accept_ref = Ref}};
{error, connaborted} ->
inc_stats(State, connaborted),
{error, econnaborted} ->
inc_stats(State, econnaborted),
{keep_state_and_data, {next_event, internal, accept_and_close}};
{error, closed} ->
{stop, normal, State};
Expand Down Expand Up @@ -338,7 +338,7 @@ start_connection({F, A}, Sock, UpgradeFuns) when is_function(F) ->
%% Then it should continue to accept 10 more sockets (which are all likely
%% to result in emfile error anyway) during suspending state.
async_accept(Currentstate, LSock) ->
case do_async_accept(LSock) of
case prim_inet:async_accept(LSock, -1) of
{error, Reason} when Reason =:= emfile orelse Reason =:= enfile ->
Delay = case Currentstate of
suspending ->
Expand All @@ -353,14 +353,3 @@ async_accept(Currentstate, LSock) ->
Other ->
Other
end.

%% prim_inet is a sticky module.
%% delegate the call to esockd_test_lib in tests
%% so it can be mockde.
-ifndef(TEST).
do_async_accept(LSock) ->
prim_inet:async_accept(LSock, -1).
-else.
do_async_accept(LSock) ->
esockd_test_lib:async_accept(LSock).
-endif.
6 changes: 3 additions & 3 deletions test/esockd_acceptor_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ t_einval(Config) ->
%% the Erlang VM healthy (test case may need to write files etc),
%% so we use meck to simulate one.
t_sys_limit(Config) ->
meck:new(esockd_test_lib, [passthrough, no_history]),
meck:expect(esockd_test_lib, async_accept, fun(_) -> {error, emfile} end),
meck:new(prim_inet, [passthrough, no_history, unstick]),
meck:expect(prim_inet, async_accept, fun(_, _) -> {error, emfile} end),
Port = ?PORT,
Server = start(Port, no_limit()),
try
%% acceptor to enter suspending state after started
%% because async_accept always returns {error, emfile}
ok = wait_for_counter(Config, ?COUNTER_SYS_LIMIT, {'>', 1}, 2000),
%% now unload the mock
meck:unload(esockd_test_lib),
meck:unload(prim_inet),
%% this one is closed immediately because acceptor is still in suspending state
{ok, Sock1} = connect(Port),
ok = wait_for_counter(Config, ?COUNTER_RATE_LIMITED, 1, 2000),
Expand Down
24 changes: 0 additions & 24 deletions test/esockd_test_lib.erl

This file was deleted.

0 comments on commit 69ffe5a

Please sign in to comment.