@@ -30,7 +30,12 @@ all() ->
30
30
groups () ->
31
31
[
32
32
{non_parallel_tests , [], [
33
- routing_test ,
33
+ routing_key_hashing_test ,
34
+ custom_header_hashing_test ,
35
+ message_id_hashing_test ,
36
+ correlation_id_hashing_test ,
37
+ timestamp_hashing_test ,
38
+ other_routing_test ,
34
39
test_binding_queue_cleanup ,
35
40
test_binding_exchange_cleanup ,
36
41
test_bucket_sizes
@@ -72,22 +77,34 @@ end_per_testcase(Testcase, Config) ->
72
77
% % Test cases
73
78
% % -------------------------------------------------------------------
74
79
75
- routing_test (Config ) ->
76
- routing_test0 (Config , [<<" q0" >>, <<" q1" >>, <<" q2" >>, <<" q3" >>]),
77
- ok .
80
+ -define (Qs , [<<" q0" >>, <<" q1" >>, <<" q2" >>, <<" q3" >>]).
81
+ % % N.B. lowering this value below 100K increases the probability
82
+ % % of failing the Chi squared test in some environments
83
+ -define (DEFAULT_SAMPLE_COUNT , 150000 ).
84
+
85
+ routing_key_hashing_test (Config ) ->
86
+ ok = test_with_rk (Config , ? Qs ).
87
+
88
+ custom_header_hashing_test (Config ) ->
89
+ ok = test_with_header (Config , ? Qs ).
90
+
91
+ message_id_hashing_test (Config ) ->
92
+ ok = test_with_message_id (Config , ? Qs ).
93
+
94
+ correlation_id_hashing_test (Config ) ->
95
+ ok = test_with_correlation_id (Config , ? Qs ).
78
96
79
- routing_test0 (Config , Qs ) ->
80
- ok = test_with_rk (Config , Qs ),
81
- ok = test_with_header (Config , Qs ),
97
+ timestamp_hashing_test (Config ) ->
98
+ ok = test_with_timestamp (Config , ? Qs ).
99
+
100
+ other_routing_test (Config ) ->
82
101
ok = test_binding_with_negative_routing_key (Config ),
83
102
ok = test_binding_with_non_numeric_routing_key (Config ),
84
- ok = test_with_correlation_id (Config , Qs ),
85
- ok = test_with_message_id (Config , Qs ),
86
- ok = test_with_timestamp (Config , Qs ),
87
103
ok = test_non_supported_property (Config ),
88
104
ok = test_mutually_exclusive_arguments (Config ),
89
105
ok .
90
106
107
+
91
108
% % -------------------------------------------------------------------
92
109
% % Implementation
93
110
% % -------------------------------------------------------------------
@@ -109,7 +126,6 @@ test_with_header(Config, Qs) ->
109
126
# amqp_msg {props = # 'P_basic' {headers = H }, payload = <<>>}
110
127
end , [{<<" hash-header" >>, longstr , <<" hashme" >>}], Qs ).
111
128
112
-
113
129
test_with_correlation_id (Config , Qs ) ->
114
130
test0 (Config , fun (E ) ->
115
131
# 'basic.publish' {exchange = E }
@@ -131,7 +147,7 @@ test_with_timestamp(Config, Qs) ->
131
147
# 'basic.publish' {exchange = E }
132
148
end ,
133
149
fun () ->
134
- # amqp_msg {props = # 'P_basic' {timestamp = rndint ()}, payload = <<>>}
150
+ # amqp_msg {props = # 'P_basic' {timestamp = rnd_int ()}, payload = <<>>}
135
151
end , [{<<" hash-property" >>, longstr , <<" timestamp" >>}], Qs ).
136
152
137
153
test_mutually_exclusive_arguments (Config ) ->
@@ -164,13 +180,15 @@ test_non_supported_property(Config) ->
164
180
ok .
165
181
166
182
rnd () ->
167
- list_to_binary (integer_to_list (rndint ())).
183
+ list_to_binary (integer_to_list (rnd_int ())).
168
184
169
- rndint () ->
170
- rand :uniform (1000000 ).
185
+ rnd_int () ->
186
+ rand :uniform (10000000 ).
171
187
172
188
test0 (Config , MakeMethod , MakeMsg , DeclareArgs , [Q1 , Q2 , Q3 , Q4 ] = Queues ) ->
173
- Count = 100000 ,
189
+ test0 (Config , MakeMethod , MakeMsg , DeclareArgs , [Q1 , Q2 , Q3 , Q4 ] = Queues , ? DEFAULT_SAMPLE_COUNT ).
190
+
191
+ test0 (Config , MakeMethod , MakeMsg , DeclareArgs , [Q1 , Q2 , Q3 , Q4 ] = Queues , IterationCount ) ->
174
192
Chan = rabbit_ct_client_helpers :open_channel (Config , 0 ),
175
193
# 'confirm.select_ok' {} = amqp_channel :call (Chan , # 'confirm.select' {}),
176
194
@@ -202,7 +220,7 @@ test0(Config, MakeMethod, MakeMsg, DeclareArgs, [Q1, Q2, Q3, Q4] = Queues) ->
202
220
203
221
[amqp_channel :call (Chan ,
204
222
MakeMethod (CHX ),
205
- MakeMsg ()) || _ <- lists :duplicate (Count , const )],
223
+ MakeMsg ()) || _ <- lists :duplicate (IterationCount , const )],
206
224
amqp_channel :wait_for_confirms (Chan , 5000 ),
207
225
timer :sleep (500 ),
208
226
@@ -213,15 +231,17 @@ test0(Config, MakeMethod, MakeMsg, DeclareArgs, [Q1, Q2, Q3, Q4] = Queues) ->
213
231
exclusive = true }),
214
232
M
215
233
end || Q <- Queues ],
216
- Count = lists :sum (Counts ), % % All messages got routed
234
+ IterationCount = lists :sum (Counts ), % % All messages got routed
217
235
218
236
% % Chi-square test
219
237
% % H0: routing keys are not evenly distributed according to weight
220
- Expected = [Count div 6 , Count div 6 , (Count div 6 ) * 2 , (Count div 6 ) * 2 ],
238
+ Expected = [IterationCount div 6 , IterationCount div 6 , (IterationCount div 6 ) * 2 , (IterationCount div 6 ) * 2 ],
221
239
Obs = lists :zip (Counts , Expected ),
222
240
Chi = lists :sum ([((O - E ) * (O - E )) / E || {O , E } <- Obs ]),
223
- ct :pal (" Chi-square test for 3 degrees of freedom is ~p , p = 0.01 is 11.35" ,
224
- [Chi ]),
241
+ ct :pal (" Chi-square test for 3 degrees of freedom is ~p , p = 0.01 is 11.35, observations (counts, expected): ~p " ,
242
+ [Chi , Obs ]),
243
+ % % N.B. we need at least 100K iterations to reliably pass this test in multiple different
244
+ % % environments
225
245
? assert (Chi < 11.35 ),
226
246
227
247
clean_up_test_topology (Config , CHX , Queues ),
@@ -433,8 +453,7 @@ count_all_queue_buckets(Config) ->
433
453
[rabbit_exchange_type_consistent_hash_bucket_queue , size ]).
434
454
435
455
clean_up_test_topology (Config ) ->
436
- Qs = [<<" q0" >>, <<" q1" >>, <<" q2" >>, <<" q3" >>],
437
- clean_up_test_topology (Config , <<" e" >>, Qs ).
456
+ clean_up_test_topology (Config , <<" e" >>, ? Qs ).
438
457
439
458
clean_up_test_topology (Config , X , Qs ) ->
440
459
Ch = rabbit_ct_client_helpers :open_channel (Config , 0 ),
0 commit comments