fix(test): пропускать посторонние WS-сообщения при ожидании node_metric.
CI / test (push) Successful in 22m0s
CI / test (push) Successful in 22m0s
На shared IFT в /admin/ws/metrics приходил report_created от других тестов/активности. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -153,8 +153,8 @@ test_admin_ws_node_metrics(Url, Token) ->
|
||||
ok = test_ws_send(WS, #{action => <<"ping">>}),
|
||||
{ok, #{<<"status">> := <<"pong">>}} = test_ws_recv(WS, 3000),
|
||||
ct:pal(" Ping/Pong OK – waiting for node metric..."),
|
||||
case test_ws_recv(WS, 15000) of
|
||||
{ok, #{<<"type">> := <<"node_metric">>, <<"data">> := MetricData}} ->
|
||||
case test_ws_recv_type(WS, <<"node_metric">>, 15000) of
|
||||
{ok, #{<<"data">> := MetricData}} ->
|
||||
ct:pal(" OK - Received node metric"),
|
||||
?assert(is_map(MetricData)),
|
||||
?assert(maps:is_key(<<"timestamp">>, MetricData)),
|
||||
@@ -164,10 +164,7 @@ test_admin_ws_node_metrics(Url, Token) ->
|
||||
[maps:get(<<"node">>, MetricData),
|
||||
maps:get(<<"memory_total">>, MetricData) div 1048576]);
|
||||
{error, timeout} ->
|
||||
ct:pal(" WARNING: No node metric received (timeout) – check monitor logs");
|
||||
Other ->
|
||||
ct:pal(" ERROR: Unexpected response: ~p", [Other]),
|
||||
?assert(false, {unexpected_ws_message, Other})
|
||||
ct:pal(" WARNING: No node metric received (timeout) – check monitor logs")
|
||||
end,
|
||||
test_ws_close(WS).
|
||||
|
||||
@@ -287,6 +284,26 @@ test_ws_recv(ConnPid, Timeout) ->
|
||||
{error, timeout}
|
||||
end.
|
||||
|
||||
%% @doc Ждём WS-сообщение заданного type, пропуская посторонние (шум на shared stand).
|
||||
test_ws_recv_type(ConnPid, ExpectedType, Timeout) ->
|
||||
Deadline = erlang:monotonic_time(millisecond) + Timeout,
|
||||
test_ws_recv_type_loop(ConnPid, ExpectedType, Deadline).
|
||||
|
||||
test_ws_recv_type_loop(ConnPid, ExpectedType, Deadline) ->
|
||||
Remaining = max(0, Deadline - erlang:monotonic_time(millisecond)),
|
||||
case test_ws_recv(ConnPid, Remaining) of
|
||||
{ok, #{<<"type">> := ExpectedType} = Msg} ->
|
||||
{ok, Msg};
|
||||
{ok, #{<<"type">> := ActualType} = Other} ->
|
||||
ct:pal(" Skipping WS type=~s (waiting for ~s)", [ActualType, ExpectedType]),
|
||||
test_ws_recv_type_loop(ConnPid, ExpectedType, Deadline);
|
||||
{ok, Other} ->
|
||||
ct:pal(" Skipping WS message ~p (waiting for type ~s)", [Other, ExpectedType]),
|
||||
test_ws_recv_type_loop(ConnPid, ExpectedType, Deadline);
|
||||
{error, timeout} = Err ->
|
||||
Err
|
||||
end.
|
||||
|
||||
test_ws_close(ConnPid) ->
|
||||
gun:close(ConnPid).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user