Skip to content

Commit 64e09f1

Browse files
authored
Fix lint failures in Complement tests (#19855)
Running `scripts-dev/lint.sh` locally revealed a failure, so here are the fixes that the linter applied + a manual change to address an issue that couldn't be auto-fixed.
1 parent 51805a0 commit 64e09f1

3 files changed

Lines changed: 48 additions & 43 deletions

File tree

.github/workflows/tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ jobs:
6060
- 'poetry.lock'
6161
- 'docker/**'
6262
- '.ci/**'
63-
- 'scripts-dev/complement.sh'
6463
- '.github/workflows/tests.yml'
64+
- 'scripts-dev/complement.sh'
6565
- '.github/workflows/complement_tests.yml'
66+
- 'complement/**'
6667
6768
linting:
6869
- 'synapse/**'

changelog.d/19855.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Provide remote servers a way to find out about an event created during the remote join handshake. Contributed by @FrenchGithubUser and @jason-famedly @ Famedly.

complement/tests/federation_room_join_test.go

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -68,53 +68,56 @@ func TestEventBetweenMakeJoinAndSendJoinIsNotLost(t *testing.T) {
6868
// Complement server is not fully in the room until send_join completes, so
6969
// we can't use HandleTransactionRequests (which requires the room in
7070
// srv.rooms). Instead we parse the raw transaction body ourselves.
71-
srv.Mux().Handle("/_matrix/federation/v1/send/{transactionID}", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
72-
body, err := io.ReadAll(req.Body)
73-
must.NotError(t, "failed to read request body in /send handler: %v", err)
74-
txn := gjson.ParseBytes(body)
75-
txn.Get("pdus").ForEach(func(_, pdu gjson.Result) bool {
76-
eventID := pdu.Get("event_id").String()
77-
eventType := pdu.Get("type").String()
78-
t.Logf("Received PDU via /send: type=%s id=%s", eventType, eventID)
79-
80-
// messageEventID is set after make_join but before send_join.
81-
// Transactions can arrive before that window, so skip PDUs that
82-
// arrive before we know which event to look for.
83-
msgID, _ := messageEventID.Load().(string)
84-
if msgID == "" {
85-
return true
86-
}
71+
srv.Mux().
72+
Handle("/_matrix/federation/v1/send/{transactionID}", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
73+
body, err := io.ReadAll(req.Body)
74+
must.NotError(t, "failed to read request body in /send handler: %v", err)
75+
txn := gjson.ParseBytes(body)
76+
txn.Get("pdus").ForEach(func(_, pdu gjson.Result) bool {
77+
eventID := pdu.Get("event_id").String()
78+
eventType := pdu.Get("type").String()
79+
t.Logf("Received PDU via /send: type=%s id=%s", eventType, eventID)
80+
81+
// messageEventID is set after make_join but before send_join.
82+
// Transactions can arrive before that window, so skip PDUs that
83+
// arrive before we know which event to look for.
84+
msgID, _ := messageEventID.Load().(string)
85+
if msgID == "" {
86+
return true
87+
}
8788

88-
// Check if this IS the message event (server pushed it directly).
89-
if eventID == msgID {
90-
messageDiscoverableWaiter.Finish()
91-
return true
92-
}
93-
94-
// Check if this event's prev_events directly reference the message (e.g. a dummy
95-
// event tying the two forward extremities together). If so, the joining server
96-
// can backfill from that event and will discover the message.
97-
//
98-
// XXX: We only check one level of prev_events: if the reference is deeper in the
99-
// DAG, it's valid and the joining server can still reach the message through
100-
// backfill but our checks don't account for that yet (feel free to edit this
101-
// assertion if you run into this)
102-
pdu.Get("prev_events").ForEach(func(_, prevEvent gjson.Result) bool {
103-
if prevEvent.String() == msgID {
89+
// Check if this IS the message event (server pushed it directly).
90+
if eventID == msgID {
10491
messageDiscoverableWaiter.Finish()
105-
return false
92+
return true
10693
}
94+
95+
// Check if this event's prev_events directly reference the message (e.g. a dummy
96+
// event tying the two forward extremities together). If so, the joining server
97+
// can backfill from that event and will discover the message.
98+
//
99+
// XXX: We only check one level of prev_events: if the reference is deeper in the
100+
// DAG, it's valid and the joining server can still reach the message through
101+
// backfill but our checks don't account for that yet (feel free to edit this
102+
// assertion if you run into this)
103+
pdu.Get("prev_events").ForEach(func(_, prevEvent gjson.Result) bool {
104+
if prevEvent.String() == msgID {
105+
messageDiscoverableWaiter.Finish()
106+
return false
107+
}
108+
return true
109+
})
110+
107111
return true
108112
})
109-
110-
return true
111-
})
112-
w.WriteHeader(200)
113-
// Respond with an empty PDU error map, which is the federation /send
114-
// success response format: each key would be a PDU ID whose processing
115-
// failed; an empty object means all PDUs were accepted.
116-
w.Write([]byte(`{"pdus":{}}`))
117-
})).Methods("PUT")
113+
w.WriteHeader(200)
114+
// Respond with an empty PDU error map, which is the federation /send
115+
// success response format: each key would be a PDU ID whose processing
116+
// failed; an empty object means all PDUs were accepted.
117+
_, err = w.Write([]byte(`{"pdus":{}}`))
118+
must.NotError(t, "failed to write response body in /send handler: %v", err)
119+
})).
120+
Methods("PUT")
118121

119122
cancel := srv.Listen()
120123
defer cancel()

0 commit comments

Comments
 (0)