Skip to content

Commit

Permalink
test: cover listener socket close
Browse files Browse the repository at this point in the history
  • Loading branch information
zmstone committed Nov 12, 2024
1 parent 1814bac commit b8fce2a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/esockd_acceptor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
Expand Down
24 changes: 24 additions & 0 deletions test/esockd_acceptor_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8fce2a

Please sign in to comment.