From 69ffe5afd318e01cac2f5adafe4522cc662e390a Mon Sep 17 00:00:00 2001 From: zmstone Date: Tue, 12 Nov 2024 13:51:40 +0100 Subject: [PATCH] test: unstick prim_inet for meck --- src/esockd_acceptor.erl | 17 +++-------------- test/esockd_acceptor_SUITE.erl | 6 +++--- test/esockd_test_lib.erl | 24 ------------------------ 3 files changed, 6 insertions(+), 41 deletions(-) delete mode 100644 test/esockd_test_lib.erl diff --git a/src/esockd_acceptor.erl b/src/esockd_acceptor.erl index b7b3403..99e5e49 100644 --- a/src/esockd_acceptor.erl +++ b/src/esockd_acceptor.erl @@ -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}; @@ -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 -> @@ -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. diff --git a/test/esockd_acceptor_SUITE.erl b/test/esockd_acceptor_SUITE.erl index 6762d6b..39e0cce 100644 --- a/test/esockd_acceptor_SUITE.erl +++ b/test/esockd_acceptor_SUITE.erl @@ -154,8 +154,8 @@ 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 @@ -163,7 +163,7 @@ t_sys_limit(Config) -> %% 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), diff --git a/test/esockd_test_lib.erl b/test/esockd_test_lib.erl deleted file mode 100644 index 3f01f98..0000000 --- a/test/esockd_test_lib.erl +++ /dev/null @@ -1,24 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2024 EMQ Technologies Co., Ltd. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%%-------------------------------------------------------------------- - --module(esockd_test_lib). - --export([async_accept/1]). - -%% prim_inet call delegation for meck -%% because prim_inet is a sticky module -async_accept(LSock) -> - prim_inet:async_accept(LSock, -1).