summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorkjnilsson <knilsson@pivotal.io>2019-02-28 11:41:51 +0000
committerkjnilsson <knilsson@pivotal.io>2019-02-28 11:41:51 +0000
commit1485ca841451c50e05674fe90aa9763820464706 (patch)
treef75bcfb6836fe6a5e2406cc8e941a5e6af886520 /test
parent44928187312c9ffaaa272a4daa85211b4d400e34 (diff)
downloadrabbitmq-server-git-1485ca841451c50e05674fe90aa9763820464706.tar.gz
Ensure waiting consumers can receive credit
Else they may never be able to do any processing when they get promoted to active and AMQP 1.0 is used. [#164135123]
Diffstat (limited to 'test')
-rw-r--r--test/rabbit_fifo_SUITE.erl33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/rabbit_fifo_SUITE.erl b/test/rabbit_fifo_SUITE.erl
index a45d423e69..40884359f8 100644
--- a/test/rabbit_fifo_SUITE.erl
+++ b/test/rabbit_fifo_SUITE.erl
@@ -1085,6 +1085,39 @@ single_active_cancelled_with_unacked_test(_) ->
?assertMatch([], State6#rabbit_fifo.waiting_consumers),
ok.
+single_active_with_credited_test(_) ->
+ State0 = init(#{name => ?FUNCTION_NAME,
+ queue_resource => rabbit_misc:r("/", queue,
+ atom_to_binary(?FUNCTION_NAME, utf8)),
+ release_cursor_interval => 0,
+ single_active_consumer_on => true}),
+
+ C1 = {<<"ctag1">>, self()},
+ C2 = {<<"ctag2">>, self()},
+ % adding some consumers
+ AddConsumer = fun(C, S0) ->
+ {S, _, _} = apply(
+ meta(1),
+ make_checkout(C,
+ {auto, 0, credited},
+ #{}),
+ S0),
+ S
+ end,
+ State1 = lists:foldl(AddConsumer, State0, [C1, C2]),
+
+ %% add some credit
+ C1Cred = rabbit_fifo:make_credit(C1, 5, 0, false),
+ {State2, _, _Effects2} = apply(meta(3), C1Cred, State1),
+ C2Cred = rabbit_fifo:make_credit(C2, 4, 0, false),
+ {State3, _} = apply(meta(4), C2Cred, State2),
+ %% both consumers should have credit
+ ?assertMatch(#{C1 := #consumer{credit = 5}},
+ State3#rabbit_fifo.consumers),
+ ?assertMatch([{C2, #consumer{credit = 4}}],
+ State3#rabbit_fifo.waiting_consumers),
+ ok.
+
meta(Idx) ->
#{index => Idx, term => 1}.