Skip to content

Commit f93e37f

Browse files
committed
Make test_epmd more robust by performing an actual query on epmd
test_epmd ensured that epmd is running on CI by trying to connect to it. However, in some cases, this connection test succeeded while epmd would not be ready yet and would close the socket when trying to register. See for example this run: https://github.com/pguyot/AtomVM/actions/runs/19780234793/job/56679370750 Replace test with querying for registered nodes to ensure epmd is indeed ready. Signed-off-by: Paul Guyot <pguyot@kallisys.net>
1 parent 80d41d8 commit f93e37f

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

tests/libs/estdlib/test_epmd.erl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,14 @@ ensure_epmd("ATOM") ->
9797

9898
ensure_epmd_connect_loop(0) ->
9999
io:format("Coult not connect to epmd\n"),
100-
exit(timeout);
100+
{error, timeout};
101101
ensure_epmd_connect_loop(N) ->
102-
{ok, Socket} = socket:open(inet, stream, tcp),
103-
Result = socket:connect(Socket, #{addr => {127, 0, 0, 1}, port => ?EPMD_PORT, family => inet}),
104-
socket:close(Socket),
105-
case Result of
106-
ok ->
102+
case erl_epmd:names("127.0.0.1") of
103+
{ok, _} ->
107104
ok;
108-
{error, econnrefused} ->
109-
timer:sleep(100),
110-
ensure_epmd_connect_loop(N - 1);
111-
{error, closed} ->
112-
timer:sleep(100),
105+
{error, Reason} ->
106+
io:format("Could not connect to epmd -- error = ~p, retrying (N = ~p)\n", [Reason, N]),
107+
timer:sleep(500),
113108
ensure_epmd_connect_loop(N - 1)
114109
end.
115110

@@ -153,14 +148,24 @@ start_epmd() ->
153148
Platform = erlang:system_info(machine),
154149
case has_epmd(Platform) of
155150
true ->
156-
ok = ensure_epmd(Platform),
157-
% on CI, epmd may be slow to accept connections
158-
ensure_epmd_connect_loop(50),
159-
ok;
151+
start_epmd(Platform, 5);
160152
false ->
161153
{error, not_found}
162154
end.
163155

156+
start_epmd(_Platform, 0) ->
157+
exit(timeout);
158+
start_epmd(Platform, N) ->
159+
ok = ensure_epmd(Platform),
160+
% on CI, epmd may be slow to accept connections
161+
case ensure_epmd_connect_loop(5) of
162+
ok ->
163+
ok;
164+
{error, timeout} ->
165+
stop_epmd(Platform),
166+
start_epmd(Platform, N - 1)
167+
end.
168+
164169
stop_epmd() ->
165170
Platform = erlang:system_info(machine),
166171
case has_epmd(Platform) of

0 commit comments

Comments
 (0)