@@ -177,14 +177,20 @@ simple_sac_consumer_should_get_disconnected_on_network_partition(Config) ->
177
177
delete_stream (stream_port (Config , 0 ), S ),
178
178
179
179
% % online consumers should receive a metadata update frame (stream deleted)
180
- % % we unqueue the this frame before closing the connection
180
+ % % we unqueue this frame before closing the connection
181
181
% % directly closing the connection of the cancelled consumer
182
+ % % Edge case:
183
+ % % the waiting consumer can get 2 frames: consumer_update then metadata_update.
184
+ % % This is because the active consumer is removed from the group and this triggers
185
+ % % a rebalancing. The 2 remaining consumers are most of the time cancelled when the
186
+ % % stream is deleted, so the rebalancing does not take place.
187
+ % % We just tolerate an extra frame when closing their respective connections.
182
188
maps :foreach (fun (K , {S0 , C0 }) when K /= DiscSubId ->
183
189
log (" Expecting frame in consumer ~p " , [K ]),
184
190
{Cmd1 , C1 } = receive_commands (S0 , C0 ),
185
191
log (" Received ~p " , [Cmd1 ]),
186
192
log (" Closing" ),
187
- {ok , _ } = stream_test_utils : close (S0 , C1 );
193
+ {ok , _ } = close_connection (S0 , C1 );
188
194
(K , {S0 , C0 }) ->
189
195
log (" Closing ~p " , [K ]),
190
196
{ok , _ } = stream_test_utils :close (S0 , C0 )
@@ -290,12 +296,18 @@ simple_sac_consumer_should_get_disconnected_on_coord_leader_network_partition(Co
290
296
% % online consumers should receive a metadata update frame (stream deleted)
291
297
% % we unqueue this frame before closing the connection
292
298
% % directly closing the connection of the cancelled consumer
299
+ % % Edge case:
300
+ % % the waiting consumer can get 2 frames: consumer_update then metadata_update.
301
+ % % This is because the active consumer is removed from the group and this triggers
302
+ % % a rebalancing. The 2 remaining consumers are most of the time cancelled when the
303
+ % % stream is deleted, so the rebalancing does not take place.
304
+ % % We just tolerate an extra frame when closing their respective connections.
293
305
maps :foreach (fun (K , {S0 , C0 }) when K /= DiscSubId ->
294
306
log (" Expecting frame in consumer ~p " , [K ]),
295
307
{Cmd1 , C1 } = receive_commands (S0 , C0 ),
296
308
log (" Received ~p " , [Cmd1 ]),
297
309
log (" Closing" ),
298
- {ok , _ } = stream_test_utils : close (S0 , C1 );
310
+ {ok , _ } = close_connection (S0 , C1 );
299
311
(K , {S0 , C0 }) ->
300
312
log (" Closing ~p " , [K ]),
301
313
{ok , _ } = stream_test_utils :close (S0 , C0 )
@@ -395,12 +407,18 @@ super_stream_sac_consumer_should_get_disconnected_on_network_partition(Config) -
395
407
% % online consumers should receive a metadata update frame (stream deleted)
396
408
% % we unqueue this frame before closing the connection
397
409
% % directly closing the connection of the cancelled consumer
410
+ % % Edge case:
411
+ % % the waiting consumer can get 2 frames: consumer_update then metadata_update.
412
+ % % This is because the active consumer is removed from the group and this triggers
413
+ % % a rebalancing. The 2 remaining consumers are most of the time cancelled when the
414
+ % % stream is deleted, so the rebalancing does not take place.
415
+ % % We just tolerate an extra frame when closing their respective connections.
398
416
maps :foreach (fun (K , {S0 , C0 }) when K /= DiscSubId ->
399
417
log (" Expecting frame in consumer ~p " , [K ]),
400
418
{Cmd1 , C1 } = receive_commands (S0 , C0 ),
401
419
log (" Received ~p " , [Cmd1 ]),
402
420
log (" Closing" ),
403
- {ok , _ } = stream_test_utils : close (S0 , C1 );
421
+ {ok , _ } = close_connection (S0 , C1 );
404
422
(K , {S0 , C0 }) ->
405
423
log (" Closing ~p " , [K ]),
406
424
{ok , _ } = stream_test_utils :close (S0 , C0 )
@@ -516,12 +534,18 @@ super_stream_sac_consumer_should_get_disconnected_on_coord_leader_network_partit
516
534
% % online consumers should receive a metadata update frame (stream deleted)
517
535
% % we unqueue this frame before closing the connection
518
536
% % directly closing the connection of the cancelled consumer
537
+ % % Edge case:
538
+ % % the waiting consumer can get 2 frames: consumer_update then metadata_update.
539
+ % % This is because the active consumer is removed from the group and this triggers
540
+ % % a rebalancing. The 2 remaining consumers are most of the time cancelled when the
541
+ % % stream is deleted, so the rebalancing does not take place.
542
+ % % We just tolerate an extra frame when closing their respective connections.
519
543
maps :foreach (fun (K , {S0 , C0 }) when K /= DiscSubId ->
520
544
log (" Expecting frame in consumer ~p " , [K ]),
521
545
{Cmd1 , C1 } = receive_commands (S0 , C0 ),
522
546
log (" Received ~p " , [Cmd1 ]),
523
547
log (" Closing" ),
524
- {ok , _ } = stream_test_utils : close (S0 , C1 );
548
+ {ok , _ } = close_connection (S0 , C1 );
525
549
(K , {S0 , C0 }) ->
526
550
log (" Closing ~p " , [K ]),
527
551
{ok , _ } = stream_test_utils :close (S0 , C0 )
@@ -858,3 +882,19 @@ log(Format) ->
858
882
859
883
log (Format , Args ) ->
860
884
ct :pal (Format , Args ).
885
+
886
+ close_connection (Sock , C ) ->
887
+ CloseReason = <<" OK" >>,
888
+ CloseFrame = rabbit_stream_core :frame ({request , 1 , {close , ? RESPONSE_CODE_OK , CloseReason }}),
889
+ ok = gen_tcp :send (Sock , CloseFrame ),
890
+ pump_until_close (Sock , C , 10 ).
891
+
892
+ pump_until_close (_ , _ , 0 ) ->
893
+ ct :fail (" did not get close response" );
894
+ pump_until_close (Sock , C0 , N ) ->
895
+ case stream_test_utils :receive_stream_commands (Sock , C0 ) of
896
+ {{response , 1 , {close , ? RESPONSE_CODE_OK }}, C1 } ->
897
+ {ok , C1 };
898
+ {_Cmd , C1 } ->
899
+ pump_until_close (Sock , C1 , N - 1 )
900
+ end .
0 commit comments