Skip to content

Commit

Permalink
Add test to make sure you can find imported events before room creation
Browse files Browse the repository at this point in the history
Synapse changes: matrix-org/synapse#13197
  • Loading branch information
MadLittleMods committed Jul 6, 2022
1 parent 38dfe7b commit 83eb881
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions tests/msc3030_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import (

"github.com/matrix-org/complement/internal/b"
"github.com/matrix-org/complement/internal/client"
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
)

func TestJumpToDateEndpoint(t *testing.T) {
deployment := Deploy(t, b.BlueprintFederationTwoLocalOneRemote)
deployment := Deploy(t, b.BlueprintHSWithApplicationService)
defer deployment.Destroy(t)

// Create the normal user which will send messages in the room
Expand All @@ -31,6 +32,10 @@ func TestJumpToDateEndpoint(t *testing.T) {
remoteUserID := "@charlie:hs2"
remoteCharlie := deployment.Client(t, "hs2", remoteUserID)

// Create the application service bridge user that can use the ?ts query parameter
asUserID := "@the-bridge-user:hs1"
as := deployment.Client(t, "hs1", asUserID)

t.Run("parallel", func(t *testing.T) {
t.Run("should find event after given timestmap", func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -127,6 +132,38 @@ func TestJumpToDateEndpoint(t *testing.T) {
remoteCharlie.JoinRoom(t, roomID, []string{"hs1"})
mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, eventB.AfterTimestamp, "b", eventB.EventID)
})

t.Run("when looking backwards before the room was created, should be able to find event that was imported", func(t *testing.T) {
t.Parallel()
timeBeforeRoomCreation := time.Now()
roomID, _, _ := createTestRoom(t, alice)

// Join from the application service bridge user
as.JoinRoom(t, roomID, []string{"hs1"})

// Import a message in the room before the room was created. We have to
// use the application service user because they are the only ones
// allowed to use the `?ts` query parameter.
importTime := time.Date(2022, 01, 03, 0, 0, 0, 0, time.Local)
importTimestamp := makeTimestampFromTime(importTime)
timestampString := strconv.FormatInt(importTimestamp, 10)
// We can't use as.SendEventSynced(...) because application services can't use the /sync API
sendRes := as.DoFunc(t, "PUT", []string{"_matrix", "client", "r0", "rooms", roomID, "send", "m.room.message", getTxnID("findEventBeforeCreation-txn")}, client.WithContentType("application/json"), client.WithJSONBody(t, map[string]interface{}{
"body": "old imported event",
"msgtype": "m.text",
}), client.WithQueries(url.Values{
"ts": []string{timestampString},
}))
sendBody := client.ParseJSON(t, sendRes)
importedEventID := client.GetJSONFieldStr(t, sendBody, "event_id")
// Make sure the imported event has reached the homeserver
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(ev gjson.Result) bool {
return ev.Get("event_id").Str == importedEventID
}))

remoteCharlie.JoinRoom(t, roomID, []string{"hs1"})
mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, timeBeforeRoomCreation, "b", importedEventID)
})
})
})
}
Expand Down Expand Up @@ -190,8 +227,10 @@ func mustCheckEventisReturnedForTime(t *testing.T, c *client.CSAPI, roomID strin
t.Fatalf("mustCheckEventisReturnedForTime: /timestamp_to_event request failed with status=%d", timestampToEventRes.StatusCode)
}

debugMessageList := getDebugMessageListFromMessagesResponse(t, c, roomID, expectedEventId, actualEventId, givenTimestamp)
fmt.Fprintf(logrus.StandardLogger().Out, debugMessageList)

if actualEventId != expectedEventId {
debugMessageList := getDebugMessageListFromMessagesResponse(t, c, roomID, expectedEventId, actualEventId, givenTimestamp)
t.Fatalf(
"Want %s given %s but got %s\n%s",
decorateStringWithAnsiColor(expectedEventId, AnsiColorGreen),
Expand Down

0 comments on commit 83eb881

Please sign in to comment.