@@ -646,7 +646,7 @@ connection_reconnected_simple_disconnected_becomes_connected_test(_) ->
646
646
Groups0 = #{GId => Group },
647
647
State0 = state (Groups0 ),
648
648
649
- Cmd = connection_reconnection_command (Pid0 ),
649
+ Cmd = connection_reconnected_command (Pid0 ),
650
650
{#? STATE {groups = Groups1 }, ok , Eff } = ? MOD :apply (Cmd , State0 ),
651
651
652
652
assertHasGroup (GId , cgroup ([consumer (Pid0 , 0 , {connected , active }),
@@ -670,7 +670,7 @@ connection_reconnected_simple_active_should_be_first_test(_) ->
670
670
Groups0 = #{GId => Group },
671
671
State0 = state (Groups0 ),
672
672
673
- Cmd = connection_reconnection_command (Pid0 ),
673
+ Cmd = connection_reconnected_command (Pid0 ),
674
674
{#? STATE {groups = Groups1 }, ok , Eff } = ? MOD :apply (Cmd , State0 ),
675
675
676
676
assertHasGroup (GId , cgroup ([consumer (Pid1 , 1 , {connected , active }),
@@ -692,7 +692,7 @@ connection_reconnected_super_disconnected_becomes_connected_test(_) ->
692
692
Groups0 = #{GId => Group },
693
693
State0 = state (Groups0 ),
694
694
695
- Cmd = connection_reconnection_command (Pid0 ),
695
+ Cmd = connection_reconnected_command (Pid0 ),
696
696
{#? STATE {groups = Groups1 }, ok , Eff } = ? MOD :apply (Cmd , State0 ),
697
697
698
698
assertHasGroup (GId , cgroup (1 , [consumer (Pid0 , 0 , {connected , waiting }),
@@ -724,7 +724,7 @@ forget_connection_simple_disconnected_becomes_forgotten_test(_) ->
724
724
assertSendMessageEffect (Pid1 , 1 , stream (), name (), true , Eff ),
725
725
ok .
726
726
727
- forget_connection_super_disconnected_becomes_forgotten_test (_ ) ->
727
+ forget_connection_super_stream_disconnected_becomes_forgotten_test (_ ) ->
728
728
Pid0 = spawn (fun () -> ok end ),
729
729
Pid1 = spawn (fun () -> ok end ),
730
730
Pid2 = spawn (fun () -> ok end ),
@@ -936,8 +936,153 @@ handle_connection_node_disconnected_super_stream_disconn_active_block_rebalancin
936
936
assertNodeDisconnectedTimerEffect (Pid0 , Eff ),
937
937
ok .
938
938
939
+ connection_reconnected_simple_disconn_active_block_rebalancing_test (_ ) ->
940
+ Pid0 = spawn (fun () -> ok end ),
941
+ Pid1 = spawn (fun () -> ok end ),
942
+ Pid2 = spawn (fun () -> ok end ),
943
+ GId = group_id (),
944
+ Group = cgroup ([consumer (Pid0 , 0 , {disconnected , waiting }),
945
+ consumer (Pid1 , 0 , {disconnected , active }),
946
+ consumer (Pid2 , 0 , {connected , waiting })]),
947
+
948
+ Groups0 = #{GId => Group },
949
+ State0 = state (Groups0 ),
950
+ Cmd = connection_reconnected_command (Pid0 ),
951
+ {#? STATE {groups = Groups1 }, ok , Eff } = ? MOD :apply (Cmd , State0 ),
952
+
953
+ assertHasGroup (GId , cgroup ([consumer (Pid1 , 0 , {disconnected , active }),
954
+ consumer (Pid0 , 0 , {connected , waiting }),
955
+ consumer (Pid2 , 0 , {connected , waiting })]),
956
+ Groups1 ),
957
+ assertEmpty (Eff ),
958
+ ok .
959
+
960
+ connection_reconnected_super_stream_disconn_active_block_rebalancing_test (_ ) ->
961
+ Pid0 = spawn (fun () -> ok end ),
962
+ Pid1 = spawn (fun () -> ok end ),
963
+ Pid2 = spawn (fun () -> ok end ),
964
+ GId = group_id (),
965
+ Group = cgroup (1 , [consumer (Pid0 , 0 , {disconnected , active }),
966
+ consumer (Pid1 , 0 , {disconnected , waiting }),
967
+ consumer (Pid2 , 0 , {connected , waiting })]),
968
+
969
+ Groups0 = #{GId => Group },
970
+ State0 = state (Groups0 ),
971
+ Cmd = connection_reconnected_command (Pid1 ),
972
+ {#? STATE {groups = Groups1 }, ok , Eff } = ? MOD :apply (Cmd , State0 ),
973
+
974
+ assertHasGroup (GId , cgroup (1 , [consumer (Pid0 , 0 , {disconnected , active }),
975
+ consumer (Pid1 , 0 , {connected , waiting }),
976
+ consumer (Pid2 , 0 , {connected , waiting })]),
977
+ Groups1 ),
978
+ assertEmpty (Eff ),
979
+ ok .
980
+
981
+ forget_connection_simple_disconn_active_block_rebalancing_test (_ ) ->
982
+ Pid0 = spawn (fun () -> ok end ),
983
+ Pid1 = spawn (fun () -> ok end ),
984
+ Pid2 = spawn (fun () -> ok end ),
985
+ GId = group_id (),
986
+ Group = cgroup ([consumer (Pid0 , {disconnected , waiting }),
987
+ consumer (Pid1 , {connected , waiting }),
988
+ consumer (Pid2 , {disconnected , active })]),
989
+
990
+ Groups0 = #{GId => Group },
991
+ State0 = state (Groups0 ),
992
+
993
+ {#? STATE {groups = Groups1 }, Eff } = ? MOD :forget_connection (Pid0 , State0 ),
994
+
995
+ assertHasGroup (GId , cgroup ([consumer (Pid2 , {disconnected , active }),
996
+ consumer (Pid0 , {forgotten , waiting }),
997
+ consumer (Pid1 , {connected , waiting })]),
998
+ Groups1 ),
999
+ assertEmpty (Eff ),
1000
+ ok .
1001
+
1002
+ forget_connection_super_stream_disconn_active_block_rebalancing_test (_ ) ->
1003
+ Pid0 = spawn (fun () -> ok end ),
1004
+ Pid1 = spawn (fun () -> ok end ),
1005
+ Pid2 = spawn (fun () -> ok end ),
1006
+ GId = group_id (),
1007
+ Group = cgroup (1 , [consumer (Pid0 , {disconnected , waiting }),
1008
+ consumer (Pid1 , {connected , waiting }),
1009
+ consumer (Pid2 , {disconnected , active })]),
1010
+
1011
+ Groups0 = #{GId => Group },
1012
+ State0 = state (Groups0 ),
1013
+
1014
+ {#? STATE {groups = Groups1 }, Eff } = ? MOD :forget_connection (Pid0 , State0 ),
1015
+
1016
+ assertHasGroup (GId , cgroup (1 , [consumer (Pid0 , {forgotten , waiting }),
1017
+ consumer (Pid1 , {connected , waiting }),
1018
+ consumer (Pid2 , {disconnected , active })]),
1019
+ Groups1 ),
1020
+ assertEmpty (Eff ),
1021
+ ok .
1022
+
1023
+ purge_nodes_test (_ ) ->
1024
+ N0 = node (),
1025
+ {ok , N1Pid , N1 } = peer :start (#{
1026
+ name => ? FUNCTION_NAME ,
1027
+ connection => standard_io ,
1028
+ shutdown => close
1029
+ }),
1030
+
1031
+ N0P0 = spawn (N0 , fun () -> ok end ),
1032
+ N0P1 = spawn (N0 , fun () -> ok end ),
1033
+ N0P2 = spawn (N0 , fun () -> ok end ),
1034
+ N1P0 = spawn (N1 , fun () -> ok end ),
1035
+ N1P1 = spawn (N1 , fun () -> ok end ),
1036
+ N1P2 = spawn (N1 , fun () -> ok end ),
1037
+
1038
+ S0 = <<" s0" >>,
1039
+ S1 = <<" s1" >>,
1040
+ S2 = <<" s2" >>,
1041
+
1042
+ GId0 = group_id (S0 ),
1043
+ GId1 = group_id (S1 ),
1044
+ GId2 = group_id (S2 ),
1045
+
1046
+ Group0 = cgroup ([consumer (N1P0 , {disconnected , active }),
1047
+ consumer (N0P1 , {connected , waiting }),
1048
+ consumer (N0P2 , {connected , waiting })]),
1049
+
1050
+ Group1 = cgroup (1 , [consumer (N1P1 , {disconnected , waiting }),
1051
+ consumer (N1P2 , {disconnected , active }),
1052
+ consumer (N0P0 , {connected , waiting })]),
1053
+
1054
+ Group2 = cgroup ([consumer (N0P0 , {connected , active }),
1055
+ consumer (N0P1 , {connected , waiting }),
1056
+ consumer (N0P2 , {connected , waiting })]),
1057
+
1058
+
1059
+ State0 = state (#{GId0 => Group0 , GId1 => Group1 , GId2 => Group2 }),
1060
+ Cmd = purge_nodes_command ([N1 ]),
1061
+ {#? STATE {groups = Groups1 }, ok , Eff } = ? MOD :apply (Cmd , State0 ),
1062
+
1063
+ assertSize (3 , Groups1 ),
1064
+ assertHasGroup (GId0 , cgroup ([consumer (N0P1 , {connected , active }),
1065
+ consumer (N0P2 , {connected , waiting })]),
1066
+ Groups1 ),
1067
+ assertHasGroup (GId1 , cgroup (1 , [consumer (N0P0 , {connected , active })]),
1068
+ Groups1 ),
1069
+ assertHasGroup (GId2 , cgroup ([consumer (N0P0 , {connected , active }),
1070
+ consumer (N0P1 , {connected , waiting }),
1071
+ consumer (N0P2 , {connected , waiting })]),
1072
+ Groups1 ),
1073
+
1074
+ assertSize (2 , Eff ),
1075
+ assertContainsSendMessageEffect (N0P1 , S0 , true , Eff ),
1076
+ assertContainsSendMessageEffect (N0P0 , S1 , true , Eff ),
1077
+
1078
+ _ = peer :stop (N1Pid ),
1079
+ ok .
1080
+
939
1081
group_id () ->
940
- {<<" /" >>, stream (), name ()}.
1082
+ group_id (stream ()).
1083
+
1084
+ group_id (S ) ->
1085
+ {<<" /" >>, S , name ()}.
941
1086
942
1087
stream () ->
943
1088
<<" sO" >>.
@@ -964,6 +1109,9 @@ assertHasGroup(GroupId, Group, Groups) ->
964
1109
G = maps :get (GroupId , Groups ),
965
1110
? assertEqual (Group , G ).
966
1111
1112
+ consumer (Pid , Status ) ->
1113
+ consumer (Pid , 0 , Status ).
1114
+
967
1115
consumer (Pid , SubId , {Connectivity , Status }) ->
968
1116
# consumer {pid = Pid ,
969
1117
subscription_id = SubId ,
@@ -1015,9 +1163,32 @@ activate_consumer_command(Stream, ConsumerName) ->
1015
1163
stream = Stream ,
1016
1164
consumer_name = ConsumerName }.
1017
1165
1018
- connection_reconnection_command (Pid ) ->
1166
+ connection_reconnected_command (Pid ) ->
1019
1167
# command_connection_reconnected {pid = Pid }.
1020
1168
1169
+ purge_nodes_command (Nodes ) ->
1170
+ # command_purge_nodes {nodes = Nodes }.
1171
+
1172
+
1173
+ assertContainsSendMessageEffect (Pid , Stream , Active , Effects ) ->
1174
+ assertContainsSendMessageEffect (Pid , 0 , Stream , name (), Active , Effects ).
1175
+
1176
+ assertContainsSendMessageEffect (Pid , SubId , Stream , ConsumerName , Active ,
1177
+ Effects ) ->
1178
+ Contains = lists :any (fun (Eff ) ->
1179
+ Eff =:= {mod_call ,
1180
+ rabbit_stream_sac_coordinator ,
1181
+ send_message ,
1182
+ [Pid ,
1183
+ {sac ,
1184
+ #{subscription_id => SubId ,
1185
+ stream => Stream ,
1186
+ consumer_name => ConsumerName ,
1187
+ active => Active }}]}
1188
+ end , Effects ),
1189
+ ? assert (Contains ).
1190
+
1191
+
1021
1192
assertSendMessageEffect (Pid , SubId , Stream , ConsumerName , Active , [Effect ]) ->
1022
1193
? assertEqual ({mod_call ,
1023
1194
rabbit_stream_sac_coordinator ,
0 commit comments