@@ -897,11 +897,13 @@ async def get_room_state_ids(
897897 self .assertEqual (destination , self .OTHER_SERVER_NAME )
898898 known_event_info = known_event_dict .get (event_id )
899899 if known_event_info is None :
900- self .fail (f"Event ({ event_id } ) not part of our known events list" )
900+ self .fail (
901+ f"stubbed get_room_state_ids: Event ({ event_id } ) not part of our known events list"
902+ )
901903
902904 known_event , known_event_state_list = known_event_info
903905 logger .info (
904- "stubbed get_room_state_ids destination=%s event_id=%s auth_event_ids=%s" ,
906+ "stubbed get_room_state_ids: destination=%s event_id=%s auth_event_ids=%s" ,
905907 destination ,
906908 event_id ,
907909 known_event .auth_event_ids (),
@@ -921,11 +923,13 @@ async def get_room_state(
921923 self .assertEqual (destination , self .OTHER_SERVER_NAME )
922924 known_event_info = known_event_dict .get (event_id )
923925 if known_event_info is None :
924- self .fail (f"Event ({ event_id } ) not part of our known events list" )
926+ self .fail (
927+ f"stubbed get_room_state: Event ({ event_id } ) not part of our known events list"
928+ )
925929
926930 known_event , known_event_state_list = known_event_info
927931 logger .info (
928- "stubbed get_room_state destination=%s event_id=%s auth_event_ids=%s" ,
932+ "stubbed get_room_state: destination=%s event_id=%s auth_event_ids=%s" ,
929933 destination ,
930934 event_id ,
931935 known_event .auth_event_ids (),
@@ -937,7 +941,7 @@ async def get_room_state(
937941 known_event_info = known_event_dict .get (event_id )
938942 if known_event_info is None :
939943 self .fail (
940- f"Auth event ({ auth_event_id } ) is not part of our known events list"
944+ f"stubbed get_room_state: Auth event ({ auth_event_id } ) is not part of our known events list"
941945 )
942946 known_auth_event , _ = known_event_info
943947 auth_events .append (known_auth_event )
@@ -947,13 +951,26 @@ async def get_room_state(
947951 auth_events = auth_events ,
948952 )
949953
954+ async def get_event (destination : str , event_id : str , timeout = None ):
955+ self .assertEqual (destination , self .OTHER_SERVER_NAME )
956+ known_event_info = known_event_dict .get (event_id )
957+ if known_event_info is None :
958+ self .fail (
959+ f"stubbed get_event: Event ({ event_id } ) not part of our known events list"
960+ )
961+
962+ known_event , _ = known_event_info
963+ return {"pdus" : [known_event .get_pdu_json ()]}
964+
950965 self .mock_federation_transport_client .get_room_state_ids .side_effect = (
951966 get_room_state_ids
952967 )
953968 self .mock_federation_transport_client .get_room_state .side_effect = (
954969 get_room_state
955970 )
956971
972+ self .mock_federation_transport_client .get_event .side_effect = get_event
973+
957974 # create the room
958975 room_creator = self .appservice .sender
959976 room_id = self .helper .create_room_as (
@@ -997,17 +1014,46 @@ async def get_room_state(
9971014 for state_event in state_map .values ():
9981015 _add_to_known_event_list (state_event )
9991016
1000- historical_auth_event_ids = [
1017+ # This should be the successor of the event we want to insert next to
1018+ # (the successor of event_before is event_after).
1019+ inherited_depth = event_after .depth
1020+
1021+ historical_base_auth_event_ids = [
10011022 room_create_event .event_id ,
10021023 pl_event .event_id ,
1003- as_membership_event .event_id ,
10041024 ]
10051025 historical_state_events = list (state_map .values ())
10061026 historical_state_event_ids = [
10071027 state_event .event_id for state_event in historical_state_events
10081028 ]
10091029
1010- inherited_depth = event_after .depth
1030+ maria_mxid = "@maria:test"
1031+ maria_membership_event , _ = self .get_success (
1032+ create_event (
1033+ self .hs ,
1034+ room_id = room_id ,
1035+ sender = maria_mxid ,
1036+ state_key = maria_mxid ,
1037+ type = EventTypes .Member ,
1038+ content = {
1039+ "membership" : "join" ,
1040+ },
1041+ # It all works when I add a prev_event for the floating
1042+ # insertion event but the event no longer floats.
1043+ # It's able to resolve state at the prev_events though.
1044+ # prev_event_ids=[event_before.event_id],
1045+ allow_no_prev_events = True ,
1046+ prev_event_ids = [],
1047+ auth_event_ids = historical_base_auth_event_ids ,
1048+ state_event_ids = historical_state_event_ids ,
1049+ depth = inherited_depth ,
1050+ )
1051+ )
1052+ _add_to_known_event_list (maria_membership_event , historical_state_events )
1053+
1054+ historical_state_events .append (maria_membership_event )
1055+ historical_state_event_ids .append (maria_membership_event .event_id )
1056+
10111057 batch_id = random_string (8 )
10121058 next_batch_id = random_string (8 )
10131059 insertion_event , _ = self .get_success (
@@ -1020,13 +1066,16 @@ async def get_room_state(
10201066 EventContentFields .MSC2716_NEXT_BATCH_ID : next_batch_id ,
10211067 EventContentFields .MSC2716_HISTORICAL : True ,
10221068 },
1023- # It all works when I add a prev_event for the floating
1024- # insertion event but the event no longer floats.
1025- # It's able to resolve state at the prev_events though .
1026- prev_event_ids = [event_before .event_id ],
1069+ # The difference from the actual room /batch_send is that this is normally
1070+ # floating as well. But seems to work once we connect it to the
1071+ # floating historical state chain .
1072+ prev_event_ids = [maria_membership_event .event_id ],
10271073 # allow_no_prev_events=True,
10281074 # prev_event_ids=[],
1029- auth_event_ids = historical_auth_event_ids ,
1075+ auth_event_ids = [
1076+ * historical_base_auth_event_ids ,
1077+ as_membership_event .event_id ,
1078+ ],
10301079 state_event_ids = historical_state_event_ids ,
10311080 depth = inherited_depth ,
10321081 )
@@ -1036,11 +1085,14 @@ async def get_room_state(
10361085 create_event (
10371086 self .hs ,
10381087 room_id = room_id ,
1039- sender = room_creator ,
1088+ sender = maria_mxid ,
10401089 type = EventTypes .Message ,
10411090 content = {"body" : "Historical message" , "msgtype" : "m.text" },
10421091 prev_event_ids = [insertion_event .event_id ],
1043- auth_event_ids = historical_auth_event_ids ,
1092+ auth_event_ids = [
1093+ * historical_base_auth_event_ids ,
1094+ maria_membership_event .event_id ,
1095+ ],
10441096 depth = inherited_depth ,
10451097 )
10461098 )
@@ -1056,7 +1108,10 @@ async def get_room_state(
10561108 EventContentFields .MSC2716_HISTORICAL : True ,
10571109 },
10581110 prev_event_ids = [historical_message_event .event_id ],
1059- auth_event_ids = historical_auth_event_ids ,
1111+ auth_event_ids = [
1112+ * historical_base_auth_event_ids ,
1113+ as_membership_event .event_id ,
1114+ ],
10601115 depth = inherited_depth ,
10611116 )
10621117 )
@@ -1072,7 +1127,10 @@ async def get_room_state(
10721127 EventContentFields .MSC2716_HISTORICAL : True ,
10731128 },
10741129 prev_event_ids = [event_before .event_id ],
1075- auth_event_ids = historical_auth_event_ids ,
1130+ auth_event_ids = [
1131+ * historical_base_auth_event_ids ,
1132+ as_membership_event .event_id ,
1133+ ],
10761134 state_event_ids = historical_state_event_ids ,
10771135 depth = inherited_depth ,
10781136 )
@@ -1215,7 +1273,7 @@ async def get_room_state(
12151273 if event .event_id in event_id_extra
12161274 ]
12171275 assertion_message = (
1218- "Actual events missing from expected list: %s\n Actual events contain %d additional events compared to expected: %s\n Expected event order: %s\n Actual event order: %s"
1276+ "Debug info: \n Actual events missing from expected list: %s\n Actual events contain %d additional events compared to expected: %s\n Expected event order: %s\n Actual event order: %s"
12191277 % (
12201278 json .dumps (
12211279 [_debug_event_string (event ) for event in event_diff_ordered ],
0 commit comments