Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 63fcd4e

Browse files
committed
Update backwards-extremities testcase
We can no longer poke in events with missing prevs via the C-S API, so we rewrite this to do them via the Federation API instead.
1 parent ec43ad5 commit 63fcd4e

File tree

1 file changed

+54
-18
lines changed

1 file changed

+54
-18
lines changed

tests/handlers/test_federation.py

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
from synapse.api.constants import EventTypes
1919
from synapse.api.errors import AuthError, Codes, LimitExceededError, SynapseError
2020
from synapse.api.room_versions import RoomVersions
21-
from synapse.events import EventBase
21+
from synapse.events import EventBase, make_event_from_dict
2222
from synapse.federation.federation_base import event_from_pdu_json
2323
from synapse.logging.context import LoggingContext, run_in_background
2424
from synapse.rest import admin
2525
from synapse.rest.client import login, room
26-
from synapse.types import create_requester
2726
from synapse.util.stringutils import random_string
2827

2928
from tests import unittest
29+
from tests.test_utils import event_injection
3030

3131
logger = logging.getLogger(__name__)
3232

@@ -35,7 +35,7 @@ def generate_fake_event_id() -> str:
3535
return "$fake_" + random_string(43)
3636

3737

38-
class FederationTestCase(unittest.HomeserverTestCase):
38+
class FederationTestCase(unittest.FederatingHomeserverTestCase):
3939
servlets = [
4040
admin.register_servlets,
4141
login.register_servlets,
@@ -215,41 +215,77 @@ def test_backfill_with_many_backward_extremities(self):
215215
# create the room
216216
user_id = self.register_user("kermit", "test")
217217
tok = self.login("kermit", "test")
218-
requester = create_requester(user_id)
219218

220219
room_id = self.helper.create_room_as(room_creator=user_id, tok=tok)
220+
room_version = self.get_success(self.store.get_room_version(room_id))
221+
222+
# we need a user on the remote server to be a member, so that we can send
223+
# extremity-causing events.
224+
self.get_success(
225+
event_injection.inject_member_event(
226+
self.hs, room_id, f"@user:{self.OTHER_SERVER_NAME}", "join"
227+
)
228+
)
221229

222-
ev1 = self.helper.send(room_id, "first message", tok=tok)
230+
send_result = self.helper.send(room_id, "first message", tok=tok)
231+
ev1 = self.get_success(
232+
self.store.get_event(send_result["event_id"], allow_none=False)
233+
)
234+
current_state = self.get_success(
235+
self.store.get_events_as_list(
236+
(self.get_success(self.store.get_current_state_ids(room_id))).values()
237+
)
238+
)
223239

224240
# Create "many" backward extremities. The magic number we're trying to
225241
# create more than is 5 which corresponds to the number of backward
226242
# extremities we slice off in `_maybe_backfill_inner`
243+
federation_event_handler = self.hs.get_federation_event_handler()
227244
for _ in range(0, 8):
228-
event_handler = self.hs.get_event_creation_handler()
229-
event, context = self.get_success(
230-
event_handler.create_event(
231-
requester,
245+
event = make_event_from_dict(
246+
self.add_hashes_and_signatures(
232247
{
248+
"origin_server_ts": 1,
233249
"type": "m.room.message",
234250
"content": {
235251
"msgtype": "m.text",
236252
"body": "message connected to fake event",
237253
},
238254
"room_id": room_id,
239-
"sender": user_id,
255+
"sender": f"@user:{self.OTHER_SERVER_NAME}",
256+
"prev_events": [
257+
ev1.event_id,
258+
# We're creating an backward extremity each time thanks
259+
# to this fake event
260+
generate_fake_event_id(),
261+
],
262+
# lazy: *everything* is an auth event
263+
"auth_events": [ev.event_id for ev in current_state],
264+
"depth": ev1.depth + 1,
240265
},
241-
prev_event_ids=[
242-
ev1["event_id"],
243-
# We're creating an backward extremity each time thanks
244-
# to this fake event
245-
generate_fake_event_id(),
246-
],
247-
)
266+
room_version,
267+
),
268+
room_version,
248269
)
270+
271+
# we poke this directly into _process_received_pdu, to avoid the
272+
# federation handler wanting to backfill the fake event.
249273
self.get_success(
250-
event_handler.handle_new_client_event(requester, event, context)
274+
federation_event_handler._process_received_pdu(
275+
self.OTHER_SERVER_NAME, event, state=current_state
276+
)
251277
)
252278

279+
# we should now have 8 backwards extremities.
280+
backwards_extremities = self.get_success(
281+
self.store.db_pool.simple_select_list(
282+
"event_backward_extremities",
283+
keyvalues={"room_id": room_id},
284+
retcols=["event_id"],
285+
)
286+
)
287+
self.assertEqual(len(backwards_extremities), 8)
288+
253289
current_depth = 1
254290
limit = 100
255291
with LoggingContext("receive_pdu"):

0 commit comments

Comments
 (0)