Skip to content

Commit 0a07e8b

Browse files
committed
QQ: fix SAC activation bug
unit test and initial "fix" TODO: needs a new machine version TODO: needs the same behaviour for the requeue{} command.
1 parent c688169 commit 0a07e8b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

deps/rabbit/src/rabbit_fifo.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,8 @@ return(#{} = Meta, ConsumerKey, MsgIds, IncrDelCount, Anns,
17601760
_ ->
17611761
State1
17621762
end,
1763-
checkout(Meta, State0, State2, Effects1).
1763+
{State3, Effects2} = activate_next_consumer({State2, Effects1}),
1764+
checkout(Meta, State0, State3, Effects2).
17641765

17651766
% used to process messages that are finished
17661767
complete(Meta, ConsumerKey, [MsgId],

deps/rabbit/test/rabbit_fifo_SUITE.erl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,43 @@ single_active_consumer_higher_waiting_disconnected_test(Config) ->
19161916

19171917
ok.
19181918

1919+
single_active_consumer_higher_waiting_return_test(Config) ->
1920+
S0 = init(#{name => ?FUNCTION_NAME,
1921+
queue_resource => rabbit_misc:r("/", queue, ?FUNCTION_NAME_B),
1922+
single_active_consumer_on => true}),
1923+
1924+
Pid1 = test_util:fake_pid(node()),
1925+
C1Pid = test_util:fake_pid(n1@banana),
1926+
C2Pid = test_util:fake_pid(n2@banana),
1927+
% % adding some consumers
1928+
{CK1, C1} = {?LINE, {?LINE_B, C1Pid}},
1929+
{CK2, C2} = {?LINE, {?LINE_B, C2Pid}},
1930+
Entries =
1931+
[
1932+
%% add a consumer
1933+
{CK1, make_checkout(C1, {auto, {simple_prefetch, 1}}, #{priority => 1})},
1934+
?ASSERT(#rabbit_fifo{consumers = #{CK1 := #consumer{status = up}},
1935+
waiting_consumers = []}),
1936+
1937+
%% enqueue a message
1938+
{?LINE , rabbit_fifo:make_enqueue(Pid1, 1, msg1)},
1939+
1940+
%% add a consumer with a higher priority, current is quiescing
1941+
{CK2, make_checkout(C2, {auto, {simple_prefetch, 1}}, #{priority => 2})},
1942+
?ASSERT(#rabbit_fifo{consumers = #{CK1 := #consumer{status = quiescing}},
1943+
waiting_consumers = [{CK2, _}]}),
1944+
%% C1 returns message
1945+
{?LINE, rabbit_fifo:make_return(CK1, [0])},
1946+
%% C2 should activated
1947+
?ASSERT(#rabbit_fifo{consumers = #{CK2 := #consumer{status = up,
1948+
checked_out = Ch,
1949+
credit = 0}},
1950+
waiting_consumers = [_]} when map_size(Ch) == 1)
1951+
],
1952+
{_S1, _} = run_log(Config, S0, Entries, fun single_active_invariant/1),
1953+
1954+
ok.
1955+
19191956
single_active_consumer_quiescing_disconnected_test(Config) ->
19201957
S0 = init(#{name => ?FUNCTION_NAME,
19211958
queue_resource => rabbit_misc:r("/", queue, ?FUNCTION_NAME_B),

0 commit comments

Comments
 (0)