@@ -953,7 +953,7 @@ handle_connection_node_disconnected_super_stream_disconn_active_block_rebalancin
953953 assertNodeDisconnectedTimerEffect (Pid0 , Eff ),
954954 ok .
955955
956- connection_reconnected_simple_disconn_active_block_rebalancing_test (_ ) ->
956+ connection_reconnected_simple_disconn_active_blocks_rebalancing_test (_ ) ->
957957 Pid0 = new_process (),
958958 Pid1 = new_process (),
959959 Pid2 = new_process (),
@@ -974,7 +974,73 @@ connection_reconnected_simple_disconn_active_block_rebalancing_test(_) ->
974974 assertEmpty (Eff ),
975975 ok .
976976
977- connection_reconnected_super_stream_disconn_active_block_rebalancing_test (_ ) ->
977+ connection_reconnected_simple_forg_act_disconn_active_blocks_rebalancing_test (_ ) ->
978+ P0 = new_process (),
979+ P1 = new_process (),
980+ P2 = new_process (),
981+ GId = group_id (),
982+ Group = cgroup ([consumer (P0 , 0 , {forgotten , active }),
983+ consumer (P1 , 0 , {disconnected , active }),
984+ consumer (P2 , 0 , {connected , waiting })]),
985+
986+ Groups0 = #{GId => Group },
987+ State0 = state (Groups0 ),
988+ Cmd = connection_reconnected_command (P0 ),
989+ {#? STATE {groups = Groups1 }, ok , Eff } = ? MOD :apply (Cmd , State0 ),
990+
991+ assertHasGroup (GId , cgroup ([consumer (P0 , 0 , {connected , waiting }),
992+ consumer (P1 , 0 , {disconnected , active }),
993+ consumer (P2 , 0 , {connected , waiting })]),
994+ Groups1 ),
995+ assertSize (1 , Eff ),
996+ assertContainsSendMessageSteppingDownEffect (P0 , Eff ),
997+ ok .
998+
999+ connection_reconnected_simple_forg_act_should_trigger_rebalancing_test (_ ) ->
1000+ P0 = new_process (),
1001+ P1 = new_process (),
1002+ P2 = new_process (),
1003+ GId = group_id (),
1004+ Group = cgroup ([consumer (P0 , {forgotten , active }),
1005+ consumer (P1 , {connected , active }),
1006+ consumer (P2 , {connected , waiting })]),
1007+
1008+ Groups0 = #{GId => Group },
1009+ S0 = state (Groups0 ),
1010+ Cmd0 = connection_reconnected_command (P0 ),
1011+ {#? STATE {groups = Groups1 } = S1 , ok , Eff1 } = ? MOD :apply (Cmd0 , S0 ),
1012+
1013+ assertHasGroup (GId , cgroup ([consumer (P0 , {connected , waiting }),
1014+ consumer (P1 , {connected , waiting }),
1015+ consumer (P2 , {connected , waiting })]),
1016+ Groups1 ),
1017+ assertSize (2 , Eff1 ),
1018+ assertContainsSendMessageSteppingDownEffect (P0 , 0 , stream (), name (), Eff1 ),
1019+ assertContainsSendMessageSteppingDownEffect (P1 , 0 , stream (), name (), Eff1 ),
1020+
1021+ % % activation from the first consumer stepping down
1022+ Cmd1 = activate_consumer_command (stream (), name ()),
1023+ {#? STATE {groups = Groups2 } = S2 , ok , Eff2 } = ? MOD :apply (Cmd1 , S1 ),
1024+ assertHasGroup (GId , cgroup ([consumer (P0 , {connected , active }),
1025+ consumer (P1 , {connected , waiting }),
1026+ consumer (P2 , {connected , waiting })]),
1027+ Groups2 ),
1028+ assertSize (1 , Eff2 ),
1029+ assertContainsActivateMessage (P0 , Eff2 ),
1030+
1031+ % % activation from the second consumer stepping down
1032+ % % this is expected, but should not change the state
1033+ Cmd2 = activate_consumer_command (stream (), name ()),
1034+ {#? STATE {groups = Groups3 }, ok , Eff3 } = ? MOD :apply (Cmd2 , S2 ),
1035+ assertHasGroup (GId , cgroup ([consumer (P0 , {connected , active }),
1036+ consumer (P1 , {connected , waiting }),
1037+ consumer (P2 , {connected , waiting })]),
1038+ Groups3 ),
1039+ assertEmpty (Eff3 ),
1040+
1041+ ok .
1042+
1043+ connection_reconnected_super_stream_disconn_active_blocks_rebalancing_test (_ ) ->
9781044 Pid0 = new_process (),
9791045 Pid1 = new_process (),
9801046 Pid2 = new_process (),
@@ -995,7 +1061,73 @@ connection_reconnected_super_stream_disconn_active_block_rebalancing_test(_) ->
9951061 assertEmpty (Eff ),
9961062 ok .
9971063
998- forget_connection_simple_disconn_active_block_rebalancing_test (_ ) ->
1064+ connection_reconnected_super_stream_forg_act_disconn_active_blocks_rebalancing_test (_ ) ->
1065+ P0 = new_process (),
1066+ P1 = new_process (),
1067+ P2 = new_process (),
1068+ GId = group_id (),
1069+ Group = cgroup (1 , [consumer (P0 , {forgotten , active }),
1070+ consumer (P1 , {disconnected , active }),
1071+ consumer (P2 , {connected , waiting })]),
1072+
1073+ Groups0 = #{GId => Group },
1074+ State0 = state (Groups0 ),
1075+ Cmd = connection_reconnected_command (P0 ),
1076+ {#? STATE {groups = Groups1 }, ok , Eff } = ? MOD :apply (Cmd , State0 ),
1077+
1078+ assertHasGroup (GId , cgroup (1 , [consumer (P0 , {connected , waiting }),
1079+ consumer (P1 , {disconnected , active }),
1080+ consumer (P2 , {connected , waiting })]),
1081+ Groups1 ),
1082+ assertSize (1 , Eff ),
1083+ assertContainsSendMessageSteppingDownEffect (P0 , Eff ),
1084+ ok .
1085+
1086+ connection_reconnected_super_stream_forg_act_should_trigger_rebalancing_test (_ ) ->
1087+ P0 = new_process (),
1088+ P1 = new_process (),
1089+ P2 = new_process (),
1090+ GId = group_id (),
1091+ Group = cgroup (1 , [consumer (P0 , {forgotten , active }),
1092+ consumer (P1 , {connected , waiting }),
1093+ consumer (P2 , {connected , active })]),
1094+
1095+ Groups0 = #{GId => Group },
1096+ S0 = state (Groups0 ),
1097+ Cmd0 = connection_reconnected_command (P0 ),
1098+ {#? STATE {groups = Groups1 } = S1 , ok , Eff1 } = ? MOD :apply (Cmd0 , S0 ),
1099+
1100+ assertHasGroup (GId , cgroup (1 , [consumer (P0 , {connected , waiting }),
1101+ consumer (P1 , {connected , waiting }),
1102+ consumer (P2 , {connected , waiting })]),
1103+ Groups1 ),
1104+ assertSize (2 , Eff1 ),
1105+ assertContainsSendMessageSteppingDownEffect (P0 , 0 , stream (), name (), Eff1 ),
1106+ assertContainsSendMessageSteppingDownEffect (P2 , 0 , stream (), name (), Eff1 ),
1107+
1108+ % % activation from the first consumer stepping down
1109+ Cmd1 = activate_consumer_command (stream (), name ()),
1110+ {#? STATE {groups = Groups2 } = S2 , ok , Eff2 } = ? MOD :apply (Cmd1 , S1 ),
1111+ assertHasGroup (GId , cgroup (1 , [consumer (P0 , {connected , waiting }),
1112+ consumer (P1 , {connected , active }),
1113+ consumer (P2 , {connected , waiting })]),
1114+ Groups2 ),
1115+ assertSize (1 , Eff2 ),
1116+ assertContainsActivateMessage (P1 , Eff2 ),
1117+
1118+ % % activation from the second consumer stepping down
1119+ % % this is expected, but should not change the state
1120+ Cmd2 = activate_consumer_command (stream (), name ()),
1121+ {#? STATE {groups = Groups3 }, ok , Eff3 } = ? MOD :apply (Cmd2 , S2 ),
1122+ assertHasGroup (GId , cgroup (1 , [consumer (P0 , {connected , waiting }),
1123+ consumer (P1 , {connected , active }),
1124+ consumer (P2 , {connected , waiting })]),
1125+ Groups3 ),
1126+ assertEmpty (Eff3 ),
1127+
1128+ ok .
1129+
1130+ forget_connection_simple_disconn_active_blocks_rebalancing_test (_ ) ->
9991131 Pid0 = new_process (),
10001132 Pid1 = new_process (),
10011133 Pid2 = new_process (),
@@ -1323,6 +1455,9 @@ stream() ->
13231455name () ->
13241456 <<" app" >>.
13251457
1458+ sub_id () ->
1459+ 0 .
1460+
13261461apply_ensure_monitors (Mod , Cmd , State0 ) ->
13271462 {State1 , _ , _ } = Mod :apply (Cmd , State0 ),
13281463 {State2 , _ , _ } = Mod :ensure_monitors (Cmd , State1 , #{}, []),
@@ -1343,7 +1478,7 @@ assertHasGroup(GroupId, Group, Groups) ->
13431478 ? assertEqual (Group , G ).
13441479
13451480consumer (Pid , Status ) ->
1346- consumer (Pid , 0 , Status ).
1481+ consumer (Pid , sub_id () , Status ).
13471482
13481483consumer (Pid , SubId , {Connectivity , Status }) ->
13491484 # consumer {pid = Pid ,
@@ -1408,6 +1543,10 @@ assertContainsCheckConnectionEffect(Pid, Effects) ->
14081543assertContainsSendMessageEffect (Pid , Stream , Active , Effects ) ->
14091544 assertContainsSendMessageEffect (Pid , 0 , Stream , name (), Active , Effects ).
14101545
1546+ assertContainsActivateMessage (Pid , Effects ) ->
1547+ assertContainsSendMessageEffect (Pid , sub_id (), stream (), name (),
1548+ true , Effects ).
1549+
14111550assertContainsSendMessageEffect (Pid , SubId , Stream , ConsumerName , Active ,
14121551 Effects ) ->
14131552 assertContainsSendMessageEffect (Pid , {sac ,
@@ -1417,6 +1556,19 @@ assertContainsSendMessageEffect(Pid, SubId, Stream, ConsumerName, Active,
14171556 active => Active }},
14181557 Effects ).
14191558
1559+ assertContainsSendMessageSteppingDownEffect (Pid , Effects ) ->
1560+ assertContainsSendMessageSteppingDownEffect (Pid , sub_id (), stream (),
1561+ name (), Effects ).
1562+
1563+ assertContainsSendMessageSteppingDownEffect (Pid , SubId , Stream , ConsumerName ,
1564+ Effects ) ->
1565+ assertContainsSendMessageEffect (Pid , {sac ,
1566+ #{subscription_id => SubId ,
1567+ stream => Stream ,
1568+ consumer_name => ConsumerName ,
1569+ active => false ,
1570+ stepping_down => true }}, Effects ).
1571+
14201572assertContainsSendMessageEffect (Pid , Msg , Effects ) ->
14211573 assertContainsEffect ({mod_call ,
14221574 rabbit_stream_sac_coordinator ,
0 commit comments