Skip to content

Commit 0b5cea2

Browse files
apply suggestions
1 parent f55f01b commit 0b5cea2

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

tests/federation_room_join_test.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -600,19 +600,32 @@ func TestEventBetweenMakeJoinAndSendJoinIsNotLost(t *testing.T) {
600600
srv := federation.NewServer(t, deployment,
601601
federation.HandleKeyRequests(),
602602
)
603+
// After send_join, hs1 will start sending us federation transactions via
604+
// /_matrix/federation/v1/send/{txnID}. Since we handle /send manually
605+
// below, any other requests (e.g. key fetches) that arrive unexpectedly
606+
// should be tolerated rather than treated as test failures.
603607
srv.UnexpectedRequestsAreErrors = false
604608

605-
// Custom /send handler: the Complement server won't be in the room until
606-
// send_join completes, so we can't use HandleTransactionRequests (which
607-
// requires the room in srv.rooms). Instead we parse the raw transaction.
609+
// Custom /send handler: hs1 will push new room events to us via federation
610+
// transactions once we've joined. We use a raw handler because the
611+
// Complement server is not fully in the room until send_join completes, so
612+
// we can't use HandleTransactionRequests (which requires the room in
613+
// srv.rooms). Instead we parse the raw transaction body ourselves.
608614
srv.Mux().Handle("/_matrix/federation/v1/send/{transactionID}", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
609-
body, _ := io.ReadAll(req.Body)
615+
body, err := io.ReadAll(req.Body)
616+
if err != nil {
617+
t.Fatalf("failed to read request body in /send handler: %v", err)
618+
return
619+
}
610620
txn := gjson.ParseBytes(body)
611621
txn.Get("pdus").ForEach(func(_, pdu gjson.Result) bool {
612622
eventID := pdu.Get("event_id").String()
613623
eventType := pdu.Get("type").String()
614624
t.Logf("Received PDU via /send: type=%s id=%s", eventType, eventID)
615625

626+
// messageEventID is set after make_join but before send_join.
627+
// Transactions can arrive before that window, so skip PDUs that
628+
// arrive before we know which event to look for.
616629
if messageEventID == "" {
617630
return true
618631
}
@@ -623,8 +636,12 @@ func TestEventBetweenMakeJoinAndSendJoinIsNotLost(t *testing.T) {
623636
return true
624637
}
625638

626-
// Check if this event's prev_events reference the message
627-
// (e.g. a dummy event tying the forward extremities together).
639+
// Check if this event's prev_events directly reference the message
640+
// (e.g. a dummy event tying the two forward extremities together).
641+
// If so, the joining server can backfill from that event and will
642+
// discover the message. We only check one level of prev_events:
643+
// if the reference is deeper in the DAG the joining server can
644+
// still reach the message through backfill.
628645
pdu.Get("prev_events").ForEach(func(_, prevEvent gjson.Result) bool {
629646
if prevEvent.String() == messageEventID {
630647
messageDiscoverableWaiter.Finish()
@@ -636,6 +653,9 @@ func TestEventBetweenMakeJoinAndSendJoinIsNotLost(t *testing.T) {
636653
return true
637654
})
638655
w.WriteHeader(200)
656+
// Respond with an empty PDU error map, which is the federation /send
657+
// success response format: each key would be a PDU ID whose processing
658+
// failed; an empty object means all PDUs were accepted.
639659
w.Write([]byte(`{"pdus":{}}`))
640660
})).Methods("PUT")
641661

0 commit comments

Comments
 (0)