From b8fce2a0952d92cd45b0d669ba1d1dd189075c9c Mon Sep 17 00:00:00 2001 From: zmstone Date: Mon, 11 Nov 2024 23:28:08 +0100 Subject: [PATCH] test: cover listener socket close --- src/esockd_acceptor.erl | 6 ++++-- test/esockd_acceptor_SUITE.erl | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/esockd_acceptor.erl b/src/esockd_acceptor.erl index 7a12878..b7b3403 100644 --- a/src/esockd_acceptor.erl +++ b/src/esockd_acceptor.erl @@ -232,9 +232,11 @@ handle_event(Type, Content, StateName, _) -> event_content => Content}), keep_state_and_data. -terminate(normal, _StateName, #state{}) -> +terminate(normal, _StateName, _) -> ok; -terminate(shutdown, _StateName, #state{}) -> +terminate(shutdown, _StateName, _) -> + ok; +terminate({shutdown, _}, _StateName, _) -> ok; terminate(Reason, _StateName, #state{}) -> logger:log(error, #{msg => "esockd_acceptor_terminating", reason => Reason}), diff --git a/test/esockd_acceptor_SUITE.erl b/test/esockd_acceptor_SUITE.erl index 17ca22b..17694a1 100644 --- a/test/esockd_acceptor_SUITE.erl +++ b/test/esockd_acceptor_SUITE.erl @@ -178,6 +178,30 @@ t_sys_limit(Config) -> stop(Server) end. +t_close_listener_socket_cause_acceptor_stop(_Config) -> + Port = ?PORT, + #{acceptor := Acceptor, lsock := LSock} = start(Port, no_limit()), + Mref = monitor(process, Acceptor), + unlink(Acceptor), + unlink(LSock), + {ok, Sock1} = connect(Port), + ok = assert_socket_connected(Sock1), + exit(LSock, kill), + receive + {'DOWN', Mref, process, Acceptor, Reason} -> + ?assertEqual(normal, Reason) + after + 1000 -> + error(timeout) + end, + receive + {tcp_closed, Sock1} -> + ok + after + 1000 -> + error(timeout) + end. + assert_socket_connected(Sock) -> ok = inet:setopts(Sock, [{active, true}]), receive