test(e2e): ретраи WS-коннекта — транзиентный таймаут после deploy-stage
В 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:
@@ -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]),
|
||||||
|
|||||||
@@ -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]),
|
||||||
|
|||||||
Reference in New Issue
Block a user