From ef4a9dc2a4fea1d76453ef97854f4c7e90c5d4c4 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 12 May 2020 15:32:39 +0100 Subject: [PATCH] sort events by depth because sytest makes me sad Specifically I think it's https://github.com/matrix-org/sytest/blob/4172585c2521ec6d640b4b580080276da1ab5353/lib/SyTest/Federation/Client.pm#L265 to blame here. --- federationapi/routing/join.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/federationapi/routing/join.go b/federationapi/routing/join.go index ada89e4a6..3533bbba8 100644 --- a/federationapi/routing/join.go +++ b/federationapi/routing/join.go @@ -17,6 +17,7 @@ package routing import ( "fmt" "net/http" + "sort" "time" "github.com/matrix-org/dendrite/clientapi/jsonerror" @@ -275,6 +276,12 @@ func SendJoin( } } + // sort events deterministically by depth (lower is earlier) + // We also do this because sytest's basic federation server isn't good at using the correct + // state if these lists are randomised, resulting in flakey tests. :( + sort.Sort(eventsByDepth(stateAndAuthChainResponse.StateEvents)) + sort.Sort(eventsByDepth(stateAndAuthChainResponse.AuthChainEvents)) + // https://matrix.org/docs/spec/server_server/latest#put-matrix-federation-v1-send-join-roomid-eventid return util.JSONResponse{ Code: http.StatusOK, @@ -285,3 +292,15 @@ func SendJoin( }, } } + +type eventsByDepth []gomatrixserverlib.HeaderedEvent + +func (e eventsByDepth) Len() int { + return len(e) +} +func (e eventsByDepth) Swap(i, j int) { + e[i], e[j] = e[j], e[i] +} +func (e eventsByDepth) Less(i, j int) bool { + return e[i].Depth() < e[j].Depth() +}