Skip to content

Commit aa9d67f

Browse files
committed
Merge pull request #2042 from pguyot/w51/fix-timeout-estdlib
Add receive timeouts to avoid the 20-30 mins global timeouts These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 2bd12ff + cb3de2b commit aa9d67f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

tests/libs/estdlib/test_gen_tcp.erl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ test_echo_server(SpawnControllingProcess) ->
5050
receive
5151
ready ->
5252
ok
53+
after 1000 -> throw({timeout, test_echo_server, ?LINE})
5354
end,
5455

5556
test_send_receive(Port, 10, SpawnControllingProcess),
@@ -84,6 +85,7 @@ echo(Pid, Socket) ->
8485
echo(Pid, Socket);
8586
SomethingElse ->
8687
erlang:display({echo, unexpected_message, SomethingElse})
88+
after 1000 -> throw({timeout, echo, ?LINE})
8789
end.
8890

8991
test_send_receive(Port, N, SpawnControllingProcess) ->
@@ -92,17 +94,19 @@ test_send_receive(Port, N, SpawnControllingProcess) ->
9294
false ->
9395
loop(Socket, N);
9496
true ->
95-
Pid = spawn(fun() ->
97+
Pid = spawn_link(fun() ->
9698
receive
9799
{Parent, go} ->
98100
loop(Socket, N),
99101
Parent ! done
102+
after 5000 -> throw({timeout, test_send_receive, ?LINE})
100103
end
101104
end),
102105
gen_tcp:controlling_process(Socket, Pid),
103106
Pid ! {self(), go},
104107
receive
105108
done -> ok
109+
after 5000 -> throw({timeout, test_send_receive, ?LINE})
106110
end
107111
end,
108112

@@ -122,6 +126,7 @@ loop(Socket, I) ->
122126
ok;
123127
{tcp, _OtherSocket, _OtherPacket} ->
124128
loop(Socket, I - 1)
129+
after 1000 -> throw({timeout, loop, ?LINE})
125130
end.
126131

127132
test_listen_connect_parameters() ->
@@ -218,6 +223,7 @@ test_listen_connect_parameters(
218223
receive
219224
server_done ->
220225
ok
226+
after 1000 -> throw({timeout, test_listen_connect_parameters, ?LINE})
221227
end,
222228

223229
ok = gen_tcp:close(Socket),

tests/libs/estdlib/test_tcp_socket.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ start_echo_server(_Port) ->
197197
receive
198198
ready ->
199199
ok
200+
after 10000 ->
201+
error({timeout, ?MODULE, ?LINE})
200202
end,
201203

202204
{ListenSocket, ActualPort}.
@@ -568,6 +570,8 @@ test_abandon_select() ->
568570
receive
569571
done ->
570572
ok
573+
after 10000 ->
574+
error({timeout, ?MODULE, ?LINE})
571575
end,
572576

573577
erlang:garbage_collect(),

0 commit comments

Comments
 (0)