1313
1414-compile (export_all ).
1515
16- -define (TIMEOUT , 30000 ).
16+ -define (CONSUMER_TIMEOUT , 3000 ).
17+ -define (RECEIVE_TIMEOUT , 5000 ).
18+
19+ -define (GROUP_CONFIG ,
20+ #{global_consumer_timeout => [{rabbit , [{consumer_timeout , ? CONSUMER_TIMEOUT }]},
21+ {queue_policy , []},
22+ {queue_arguments , []},
23+ {consumer_arguments , []}],
24+ queue_policy_consumer_timeout => [{rabbit , []},
25+ {queue_policy , [{<<" consumer-timeout" >>, ? CONSUMER_TIMEOUT }]},
26+ {queue_arguments , []},
27+ {consumer_arguments , []}],
28+ queue_argument_consumer_timeout => [{rabbit , []},
29+ {queue_policy , []},
30+ {queue_arguments , [{<<" x-consumer-timeout" >>, long , ? CONSUMER_TIMEOUT }]},
31+ {consumer_arguments , []}],
32+ consumer_argument_consumer_timeout => [{rabbit , []},
33+ {queue_policy , []},
34+ {queue_arguments , []},
35+ {consumer_arguments , [{<<" x-consumer-timeout" >>, long , ? CONSUMER_TIMEOUT }]}]}).
1736
1837-import (quorum_queue_utils , [wait_for_messages /2 ]).
1938
2039all () ->
2140 [
22- {group , parallel_tests }
41+ {group , global_consumer_timeout },
42+ {group , queue_policy_consumer_timeout },
43+ {group , queue_argument_consumer_timeout },
44+ {group , consumer_argument_consumer_timeout }
2345 ].
2446
2547groups () ->
26- AllTests = [consumer_timeout ,
27- consumer_timeout_basic_get ,
28- consumer_timeout_no_basic_cancel_capability
29- ],
30- [
31- {parallel_tests , [],
32- [
48+ ConsumerTests = [consumer_timeout ,
49+ consumer_timeout_no_basic_cancel_capability ],
50+ AllTests = ConsumerTests ++ [consumer_timeout_basic_get ],
51+
52+ ConsumerTestsParallel = [
53+ {classic_queue , [parallel ], ConsumerTests },
54+ {mirrored_queue , [parallel ], ConsumerTests },
55+ {quorum_queue , [parallel ], ConsumerTests }
56+ ],
57+
58+ AllTestsParallel = [
3359 {classic_queue , [parallel ], AllTests },
3460 {mirrored_queue , [parallel ], AllTests },
3561 {quorum_queue , [parallel ], AllTests }
36- ]}
62+ ],
63+ [
64+ {global_consumer_timeout , [], AllTestsParallel },
65+ {queue_policy_consumer_timeout , [], AllTestsParallel },
66+ {queue_argument_consumer_timeout , [], AllTestsParallel },
67+ {consumer_argument_consumer_timeout , [], ConsumerTestsParallel }
3768 ].
3869
3970suite () ->
@@ -55,33 +86,36 @@ end_per_suite(Config) ->
5586init_per_group (classic_queue , Config ) ->
5687 rabbit_ct_helpers :set_config (
5788 Config ,
58- [{queue_args , [{<<" x-queue-type" >>, longstr , <<" classic" >>}]},
89+ [{policy_type , <<" classic_queues" >>},
90+ {queue_args , [{<<" x-queue-type" >>, longstr , <<" classic" >>}]},
5991 {queue_durable , true }]);
6092init_per_group (quorum_queue , Config ) ->
6193 rabbit_ct_helpers :set_config (
6294 Config ,
63- [{queue_args , [{<<" x-queue-type" >>, longstr , <<" quorum" >>}]},
95+ [{policy_type , <<" quorum_queues" >>},
96+ {queue_args , [{<<" x-queue-type" >>, longstr , <<" quorum" >>}]},
6497 {queue_durable , true }]);
6598init_per_group (mirrored_queue , Config ) ->
6699 rabbit_ct_broker_helpers :set_ha_policy (Config , 0 , <<" ^max_length.*queue" >>,
67100 <<" all" >>, [{<<" ha-sync-mode" >>, <<" automatic" >>}]),
68101 Config1 = rabbit_ct_helpers :set_config (
69- Config , [{is_mirrored , true },
102+ Config , [{policy_type , <<" classic_queues" >>},
103+ {is_mirrored , true },
70104 {queue_args , [{<<" x-queue-type" >>, longstr , <<" classic" >>}]},
71105 {queue_durable , true }]),
72106 rabbit_ct_helpers :run_steps (Config1 , []);
73107init_per_group (Group , Config0 ) ->
74108 case lists :member ({group , Group }, all ()) of
75109 true ->
110+ GroupConfig = maps :get (Group , ? GROUP_CONFIG ),
76111 ClusterSize = 3 ,
77112 Config = rabbit_ct_helpers :merge_app_env (
78113 Config0 , {rabbit , [{channel_tick_interval , 1000 },
79- {quorum_tick_interval , 1000 },
80- {consumer_timeout , 5000 }]}),
114+ {quorum_tick_interval , 1000 }] ++ ? config (rabbit , GroupConfig )}),
81115 Config1 = rabbit_ct_helpers :set_config (
82116 Config , [ {rmq_nodename_suffix , Group },
83117 {rmq_nodes_count , ClusterSize }
84- ]),
118+ ] ++ GroupConfig ),
85119 rabbit_ct_helpers :run_steps (Config1 ,
86120 rabbit_ct_broker_helpers :setup_steps () ++
87121 rabbit_ct_client_helpers :setup_steps ());
@@ -92,6 +126,11 @@ init_per_group(Group, Config0) ->
92126end_per_group (Group , Config ) ->
93127 case lists :member ({group , Group }, all ()) of
94128 true ->
129+ case ? config (queue_policy , Config ) of
130+ [] -> ok ;
131+ _Policy ->
132+ rabbit_ct_broker_helpers :clear_policy (Config , 0 , <<" consumer_timeout_queue_test_policy" >>)
133+ end ,
95134 rabbit_ct_helpers :run_steps (Config ,
96135 rabbit_ct_client_helpers :teardown_steps () ++
97136 rabbit_ct_broker_helpers :teardown_steps ());
@@ -119,12 +158,12 @@ consumer_timeout(Config) ->
119158 declare_queue (Ch , Config , QName ),
120159 publish (Ch , QName , [<<" msg1" >>]),
121160 wait_for_messages (Config , [[QName , <<" 1" >>, <<" 1" >>, <<" 0" >>]]),
122- subscribe (Ch , QName , false ),
161+ subscribe (Ch , QName , false , ? config ( consumer_arguments , Config ) ),
123162 erlang :monitor (process , Conn ),
124163 erlang :monitor (process , Ch ),
125164 receive
126165 {'DOWN' , _ , process , Ch , _ } -> ok
127- after 30000 ->
166+ after ? RECEIVE_TIMEOUT ->
128167 flush (1 ),
129168 exit (channel_exit_expected )
130169 end ,
@@ -149,7 +188,7 @@ consumer_timeout_basic_get(Config) ->
149188 erlang :monitor (process , Ch ),
150189 receive
151190 {'DOWN' , _ , process , Ch , _ } -> ok
152- after 30000 ->
191+ after ? RECEIVE_TIMEOUT ->
153192 flush (1 ),
154193 exit (channel_exit_expected )
155194 end ,
@@ -187,18 +226,18 @@ consumer_timeout_no_basic_cancel_capability(Config) ->
187226 wait_for_messages (Config , [[QName , <<" 1" >>, <<" 1" >>, <<" 0" >>]]),
188227 erlang :monitor (process , Conn ),
189228 erlang :monitor (process , Ch ),
190- subscribe (Ch , QName , false ),
229+ subscribe (Ch , QName , false , ? config ( consumer_arguments , Config ) ),
191230 receive
192231 {# 'basic.deliver' {delivery_tag = _ ,
193232 redelivered = false }, _ } ->
194233 % % do nothing with the delivery should trigger timeout
195234 ok
196- after 5000 ->
235+ after ? RECEIVE_TIMEOUT ->
197236 exit (deliver_timeout )
198237 end ,
199238 receive
200239 {'DOWN' , _ , process , Ch , _ } -> ok
201- after 30000 ->
240+ after ? RECEIVE_TIMEOUT ->
202241 flush (1 ),
203242 exit (channel_exit_expected )
204243 end ,
@@ -217,8 +256,14 @@ consumer_timeout_no_basic_cancel_capability(Config) ->
217256declare_queue (Ch , Config , QName ) ->
218257 Args = ? config (queue_args , Config ),
219258 Durable = ? config (queue_durable , Config ),
259+ case ? config (queue_policy , Config ) of
260+ [] -> ok ;
261+ Policy ->
262+ rabbit_ct_broker_helpers :set_policy (Config , 0 , <<" consumer_timeout_queue_test_policy" >>,
263+ <<" .*" >>, ? config (policy_type , Config ), Policy )
264+ end ,
220265 # 'queue.declare_ok' {} = amqp_channel :call (Ch , # 'queue.declare' {queue = QName ,
221- arguments = Args ,
266+ arguments = Args ++ ? config ( queue_arguments , Config ) ,
222267 durable = Durable }).
223268publish (Ch , QName , Payloads ) ->
224269 [amqp_channel :call (Ch , # 'basic.publish' {routing_key = QName }, # amqp_msg {payload = Payload })
@@ -235,13 +280,15 @@ consume(Ch, QName, NoAck, Payloads) ->
235280 DTag
236281 end || Payload <- Payloads ].
237282
238- subscribe (Ch , Queue , NoAck ) ->
239- subscribe (Ch , Queue , NoAck , <<" ctag" >>).
283+ subscribe (Ch , Queue , NoAck , Args ) ->
284+ subscribe (Ch , Queue , NoAck , <<" ctag" >>, Args ).
240285
241- subscribe (Ch , Queue , NoAck , Ctag ) ->
286+ subscribe (Ch , Queue , NoAck , Ctag , Args ) ->
242287 amqp_channel :subscribe (Ch , # 'basic.consume' {queue = Queue ,
243288 no_ack = NoAck ,
244- consumer_tag = Ctag },
289+ consumer_tag = Ctag ,
290+ arguments = Args
291+ },
245292 self ()),
246293 receive
247294 # 'basic.consume_ok' {consumer_tag = Ctag } ->
0 commit comments