Skip to content

Pull from socket up to 10 times in stream test utils (backport #13588) (backport #13598) #13599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions deps/rabbitmq_ct_helpers/src/stream_test_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ subscribe(Sock, C0, Stream, SubscriptionId, InitialCredit) ->
{{response, 1, {subscribe, ?RESPONSE_CODE_OK}}, C1} = receive_stream_commands(Sock, C0),
{ok, C1}.

credit(Sock, Subscription, Credit) ->
CreditFrame = rabbit_stream_core:frame({credit, Subscription, Credit}),
ok = gen_tcp:send(Sock, CreditFrame),
ok.

unsubscribe(Sock, C0, SubscriptionId) ->
UnsubscribeFrame = rabbit_stream_core:frame({request, 1, {unsubscribe, SubscriptionId}}),
ok = gen_tcp:send(Sock, UnsubscribeFrame),
Expand Down Expand Up @@ -149,20 +154,22 @@ sub_batch_entry_compressed(Sequence, Bodies) ->
<<Sequence:64, 1:1, 1:3, 0:4, (length(Bodies)):16, (byte_size(Uncompressed)):32,
CompressedLen:32, Compressed:CompressedLen/binary>>.


receive_stream_commands(Sock, C0) ->
receive_stream_commands(gen_tcp, Sock, C0).

receive_stream_commands(Transport, Sock, C0) ->
receive_stream_commands(Transport, Sock, C0, 10).

receive_stream_commands(_Transport, _Sock, C0, 0) ->
rabbit_stream_core:next_command(C0);
receive_stream_commands(Transport, Sock, C0, N) ->
case rabbit_stream_core:next_command(C0) of
empty ->
case gen_tcp:recv(Sock, 0, 5000) of
case Transport:recv(Sock, 0, 5000) of
{ok, Data} ->
C1 = rabbit_stream_core:incoming_data(Data, C0),
case rabbit_stream_core:next_command(C1) of
empty ->
{ok, Data2} = gen_tcp:recv(Sock, 0, 5000),
rabbit_stream_core:next_command(
rabbit_stream_core:incoming_data(Data2, C1));
Res ->
Res
end;
receive_stream_commands(Transport, Sock, C1, N - 1);
{error, Err} ->
ct:fail("error receiving stream data ~w", [Err])
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,8 @@ publish_via_stream_protocol(Stream, MsgPerBatch, Config) ->
{ok, C5} = stream_test_utils:publish(S, C4, PublisherId2, SequenceFrom2, Payloads2),

SubscriptionId = 97,
{ok, C6} = stream_test_utils:subscribe(S, C5, Stream, SubscriptionId, _InitialCredit = 1),
{ok, C6} = stream_test_utils:subscribe(S, C5, Stream, SubscriptionId, _InitialCredit = 0),
ok = stream_test_utils:credit(S, SubscriptionId, 1),
%% delivery of first batch of messages
{{deliver, SubscriptionId, _Bin1}, C7} = stream_test_utils:receive_stream_commands(S, C6),
{ok, S, C7}.
Expand Down
22 changes: 2 additions & 20 deletions deps/rabbitmq_stream/test/rabbit_stream_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1569,26 +1569,8 @@ wait_for_socket_close(Transport, S, Attempt) ->
closed
end.

receive_commands(Transport, S, C0) ->
case rabbit_stream_core:next_command(C0) of
empty ->
case Transport:recv(S, 0, 5000) of
{ok, Data} ->
C1 = rabbit_stream_core:incoming_data(Data, C0),
case rabbit_stream_core:next_command(C1) of
empty ->
{ok, Data2} = Transport:recv(S, 0, 5000),
rabbit_stream_core:next_command(
rabbit_stream_core:incoming_data(Data2, C1));
Res ->
Res
end;
{error, Err} ->
ct:fail("error receiving data ~w", [Err])
end;
Res ->
Res
end.
receive_commands(Transport, S, C) ->
stream_test_utils:receive_stream_commands(Transport, S, C).

get_osiris_counters(Config) ->
rabbit_ct_broker_helpers:rpc(Config,
Expand Down