@@ -40,6 +40,7 @@ routing_tests() ->
40
40
[
41
41
routing_key_hashing_test ,
42
42
custom_header_hashing_test ,
43
+ custom_header_undefined ,
43
44
message_id_hashing_test ,
44
45
correlation_id_hashing_test ,
45
46
timestamp_hashing_test ,
@@ -121,7 +122,7 @@ end_per_testcase(Testcase, Config) ->
121
122
122
123
% % N.B. lowering this value below 100K increases the probability
123
124
% % of failing the Chi squared test in some environments
124
- -define (DEFAULT_SAMPLE_COUNT , 150000 ).
125
+ -define (DEFAULT_SAMPLE_COUNT , 150_000 ).
125
126
126
127
routing_key_hashing_test (Config ) ->
127
128
ok = test_with_rk (Config , ? RoutingTestQs ).
@@ -145,6 +146,43 @@ other_routing_test(Config) ->
145
146
ok = test_mutually_exclusive_arguments (Config ),
146
147
ok .
147
148
149
+ % % Test case for
150
+ % % https://github.com/rabbitmq/rabbitmq-server/discussions/11671
151
+ % % According to our docs, it's allowed (although not recommended)
152
+ % % for the publishing client to omit the header:
153
+ % % "If published messages do not contain the header,
154
+ % % they will all get routed to the same arbitrarily chosen queue."
155
+ custom_header_undefined (Config ) ->
156
+ Exchange = <<" my exchange" >>,
157
+ Queue = <<" my queue" >>,
158
+
159
+ Ch = rabbit_ct_client_helpers :open_channel (Config ),
160
+ # 'confirm.select_ok' {} = amqp_channel :call (Ch , # 'confirm.select' {}),
161
+ # 'exchange.declare_ok' {} = amqp_channel :call (
162
+ Ch , # 'exchange.declare' {
163
+ exchange = Exchange ,
164
+ type = <<" x-consistent-hash" >>,
165
+ arguments = [{<<" hash-header" >>, longstr , <<" hashme" >>}]
166
+ }),
167
+ # 'queue.declare_ok' {} = amqp_channel :call (Ch , # 'queue.declare' {queue = Queue }),
168
+ # 'queue.bind_ok' {} = amqp_channel :call (
169
+ Ch , # 'queue.bind' {queue = Queue ,
170
+ exchange = Exchange ,
171
+ routing_key = <<" 1" >>}),
172
+
173
+ amqp_channel :call (Ch ,
174
+ # 'basic.publish' {exchange = Exchange },
175
+ % % We leave the "hashme" header undefined.
176
+ # amqp_msg {}),
177
+ amqp_channel :wait_for_confirms (Ch , 10 ),
178
+
179
+ ? assertMatch ({# 'basic.get_ok' {}, # amqp_msg {}},
180
+ amqp_channel :call (Ch , # 'basic.get' {queue = Queue })),
181
+
182
+ rabbit_ct_client_helpers :close_channel (Ch ),
183
+ clean_up_test_topology (Config , Exchange , [Queue ]),
184
+ ok .
185
+
148
186
% % Test that messages originally published with AMQP to a quorum queue
149
187
% % can be dead lettered via the consistent hash exchange to a stream.
150
188
amqp_dead_letter (Config ) ->
@@ -280,45 +318,60 @@ wait_for_accepts(N) ->
280
318
% % -------------------------------------------------------------------
281
319
282
320
test_with_rk (Config , Qs ) ->
283
- test0 (Config , fun (E ) ->
321
+ test0 (Config ,
322
+ fun (E ) ->
284
323
# 'basic.publish' {exchange = E , routing_key = rnd ()}
285
324
end ,
286
325
fun () ->
287
326
# amqp_msg {props = # 'P_basic' {}, payload = <<>>}
288
- end , [], Qs ).
327
+ end ,
328
+ [],
329
+ Qs ).
289
330
290
331
test_with_header (Config , Qs ) ->
291
- test0 (Config , fun (E ) ->
332
+ test0 (Config ,
333
+ fun (E ) ->
292
334
# 'basic.publish' {exchange = E }
293
335
end ,
294
336
fun () ->
295
337
H = [{<<" hashme" >>, longstr , rnd ()}],
296
338
# amqp_msg {props = # 'P_basic' {headers = H }, payload = <<>>}
297
- end , [{<<" hash-header" >>, longstr , <<" hashme" >>}], Qs ).
339
+ end ,
340
+ [{<<" hash-header" >>, longstr , <<" hashme" >>}],
341
+ Qs ).
298
342
299
343
test_with_correlation_id (Config , Qs ) ->
300
- test0 (Config , fun (E ) ->
344
+ test0 (Config ,
345
+ fun (E ) ->
301
346
# 'basic.publish' {exchange = E }
302
347
end ,
303
348
fun () ->
304
349
# amqp_msg {props = # 'P_basic' {correlation_id = rnd ()}, payload = <<>>}
305
- end , [{<<" hash-property" >>, longstr , <<" correlation_id" >>}], Qs ).
350
+ end ,
351
+ [{<<" hash-property" >>, longstr , <<" correlation_id" >>}],
352
+ Qs ).
306
353
307
354
test_with_message_id (Config , Qs ) ->
308
- test0 (Config , fun (E ) ->
355
+ test0 (Config ,
356
+ fun (E ) ->
309
357
# 'basic.publish' {exchange = E }
310
358
end ,
311
359
fun () ->
312
360
# amqp_msg {props = # 'P_basic' {message_id = rnd ()}, payload = <<>>}
313
- end , [{<<" hash-property" >>, longstr , <<" message_id" >>}], Qs ).
361
+ end ,
362
+ [{<<" hash-property" >>, longstr , <<" message_id" >>}],
363
+ Qs ).
314
364
315
365
test_with_timestamp (Config , Qs ) ->
316
- test0 (Config , fun (E ) ->
366
+ test0 (Config ,
367
+ fun (E ) ->
317
368
# 'basic.publish' {exchange = E }
318
369
end ,
319
370
fun () ->
320
371
# amqp_msg {props = # 'P_basic' {timestamp = rnd_int ()}, payload = <<>>}
321
- end , [{<<" hash-property" >>, longstr , <<" timestamp" >>}], Qs ).
372
+ end ,
373
+ [{<<" hash-property" >>, longstr , <<" timestamp" >>}],
374
+ Qs ).
322
375
323
376
test_mutually_exclusive_arguments (Config ) ->
324
377
Chan = rabbit_ct_client_helpers :open_channel (Config , 0 ),
@@ -359,7 +412,7 @@ test0(Config, MakeMethod, MakeMsg, DeclareArgs, Queues) ->
359
412
test0 (Config , MakeMethod , MakeMsg , DeclareArgs , Queues , ? DEFAULT_SAMPLE_COUNT ).
360
413
361
414
test0 (Config , MakeMethod , MakeMsg , DeclareArgs , [Q1 , Q2 , Q3 , Q4 ] = Queues , IterationCount ) ->
362
- Chan = rabbit_ct_client_helpers :open_channel (Config , 0 ),
415
+ Chan = rabbit_ct_client_helpers :open_channel (Config ),
363
416
# 'confirm.select_ok' {} = amqp_channel :call (Chan , # 'confirm.select' {}),
364
417
365
418
CHX = <<" e" >>,
0 commit comments