Skip to content

Commit 210d077

Browse files
committed
test: cover listener socket close
1 parent 65dcac2 commit 210d077

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/esockd_acceptor.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,11 @@ handle_event(Type, Content, StateName, _) ->
232232
event_content => Content}),
233233
keep_state_and_data.
234234

235-
terminate(normal, _StateName, #state{}) ->
235+
terminate(normal, _StateName, _) ->
236236
ok;
237-
terminate(shutdown, _StateName, #state{}) ->
237+
terminate(shutdown, _StateName, _) ->
238+
ok;
239+
terminate({shutdown, _}, _StateName, _) ->
238240
ok;
239241
terminate(Reason, _StateName, #state{}) ->
240242
logger:log(error, #{msg => "esockd_acceptor_terminating", reason => Reason}),

test/esockd_acceptor_SUITE.erl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,30 @@ t_sys_limit(Config) ->
178178
stop(Server)
179179
end.
180180

181+
t_close_listener_socket_cause_acceptor_stop(_Config) ->
182+
Port = ?PORT,
183+
#{acceptor := Acceptor, lsock := LSock} = start(Port, no_limit()),
184+
Mref = monitor(process, Acceptor),
185+
unlink(Acceptor),
186+
unlink(LSock),
187+
{ok, Sock1} = connect(Port),
188+
ok = assert_socket_connected(Sock1),
189+
exit(LSock, kill),
190+
receive
191+
{'DOWN', Mref, process, Acceptor, Reason} ->
192+
?assertEqual(normal, Reason)
193+
after
194+
1000 ->
195+
error(timeout)
196+
end,
197+
receive
198+
{tcp_closed, Sock1} ->
199+
ok
200+
after
201+
1000 ->
202+
error(timeout)
203+
end.
204+
181205
assert_socket_connected(Sock) ->
182206
ok = inet:setopts(Sock, [{active, true}]),
183207
receive

0 commit comments

Comments
 (0)