test(e2e): ретраи WS-коннекта — транзиентный таймаут после deploy-stage
CI / test (push) Successful in 7m12s
CI / deploy-ift (push) Successful in 3m49s
CI / e2e-ift (push) Successful in 1m21s
CI / deploy-stage (push) Successful in 2m58s
CI / e2e-stage (push) Successful in 1m13s

В run 621 после фикса OOM остался один упавший кейс:
admin_websocket_tests падал на gun:await_up(5000) — одиночный
TCP/TLS-таймаут в окно стабилизации traefik/бэкенда сразу после
рестарта контейнера. ws_connect_up/4 теперь ретраит коннект
3 раза с паузой 2s; одинаково в admins- и users-хелперах.
This commit is contained in:
2026-08-24 00:05:25 +03:00
parent a061674408
commit 0565f09a72
2 changed files with 52 additions and 4 deletions
+26 -2
View File
@@ -205,8 +205,7 @@ test_ws_connect_debug(Url, Token) ->
ct:pal(" Host: ~s", [Host]), ct:pal(" Host: ~s", [Host]),
ct:pal(" Port: ~p", [Port]), ct:pal(" Port: ~p", [Port]),
ct:pal(" Path: ~s", [Path]), ct:pal(" Path: ~s", [Path]),
{ok, ConnPid} = gun:open(Host, Port, Opts), ConnPid = ws_connect_up(Host, Port, Opts, 3),
{ok, http} = gun:await_up(ConnPid, 5000),
Headers = [{<<"host">>, list_to_binary(Host ++ ":" ++ integer_to_list(Port))}], Headers = [{<<"host">>, list_to_binary(Host ++ ":" ++ integer_to_list(Port))}],
StreamRef = gun:ws_upgrade(ConnPid, Path, Headers), StreamRef = gun:ws_upgrade(ConnPid, Path, Headers),
receive receive
@@ -243,6 +242,31 @@ test_ws_connect_debug(Url, Token) ->
{error, timeout} {error, timeout}
end. end.
%% @doc TCP/TLS-коннект с ретраями: сразу после deploy-stage traefik/бэкенд
%% могут быть нестабильны, и одиночный 5s-таймаут ронял сьюит
%% (badmatch {error,timeout}).
-spec ws_connect_up(string(), integer(), map(), non_neg_integer()) -> pid().
ws_connect_up(Host, Port, Opts, Retries) ->
Result =
case gun:open(Host, Port, Opts) of
{ok, ConnPid} ->
case gun:await_up(ConnPid, 5000) of
{ok, http} -> {ok, ConnPid};
{error, Reason} -> gun:close(ConnPid), {error, Reason}
end;
{error, Reason} -> {error, Reason}
end,
case Result of
{ok, Pid} -> Pid;
{error, Err} when Retries > 1 ->
ct:pal(" WS connect failed (~p), retry in 2s (~p attempts left)",
[Err, Retries - 1]),
timer:sleep(2000),
ws_connect_up(Host, Port, Opts, Retries - 1);
{error, Err} ->
error({ws_connect_failed, Err})
end.
test_ws_send(ConnPid, Data) -> test_ws_send(ConnPid, Data) ->
Msg = jsx:encode(Data), Msg = jsx:encode(Data),
ct:pal(" Sending: ~s", [Msg]), ct:pal(" Sending: ~s", [Msg]),
+26 -2
View File
@@ -91,8 +91,7 @@ test_ws_connect_debug(Url, Token) ->
ct:pal(" Host: ~s", [Host]), ct:pal(" Host: ~s", [Host]),
ct:pal(" Port: ~p", [Port]), ct:pal(" Port: ~p", [Port]),
ct:pal(" Path: ~s", [Path]), ct:pal(" Path: ~s", [Path]),
{ok, ConnPid} = gun:open(Host, Port, Opts), ConnPid = ws_connect_up(Host, Port, Opts, 3),
{ok, http} = gun:await_up(ConnPid, 5000),
Headers = [{<<"host">>, list_to_binary(Host ++ ":" ++ integer_to_list(Port))}], Headers = [{<<"host">>, list_to_binary(Host ++ ":" ++ integer_to_list(Port))}],
StreamRef = gun:ws_upgrade(ConnPid, Path, Headers), StreamRef = gun:ws_upgrade(ConnPid, Path, Headers),
receive receive
@@ -129,6 +128,31 @@ test_ws_connect_debug(Url, Token) ->
{error, timeout} {error, timeout}
end. end.
%% @doc TCP/TLS-коннект с ретраями: сразу после deploy-stage traefik/бэкенд
%% могут быть нестабильны, и одиночный 5s-таймаут ронял сьюит
%% (badmatch {error,timeout}).
-spec ws_connect_up(string(), integer(), map(), non_neg_integer()) -> pid().
ws_connect_up(Host, Port, Opts, Retries) ->
Result =
case gun:open(Host, Port, Opts) of
{ok, ConnPid} ->
case gun:await_up(ConnPid, 5000) of
{ok, http} -> {ok, ConnPid};
{error, Reason} -> gun:close(ConnPid), {error, Reason}
end;
{error, Reason} -> {error, Reason}
end,
case Result of
{ok, Pid} -> Pid;
{error, Err} when Retries > 1 ->
ct:pal(" WS connect failed (~p), retry in 2s (~p attempts left)",
[Err, Retries - 1]),
timer:sleep(2000),
ws_connect_up(Host, Port, Opts, Retries - 1);
{error, Err} ->
error({ws_connect_failed, Err})
end.
test_ws_send(ConnPid, Data) -> test_ws_send(ConnPid, Data) ->
Msg = jsx:encode(Data), Msg = jsx:encode(Data),
ct:pal(" Sending: ~s", [Msg]), ct:pal(" Sending: ~s", [Msg]),