Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for MSC2716 and backfilling history #68

Merged
merged 93 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
15ba451
Add tests for MSC2716 and backfilling history
MadLittleMods Jan 28, 2021
55c5a8c
Allow SendEventSynced to pass over prev_event querystring parameters
MadLittleMods Jan 29, 2021
70036ac
Switch to fire and forget sending over historical events which we don…
MadLittleMods Jan 29, 2021
dabdf5a
Override origin_server_ts
MadLittleMods Jan 30, 2021
6b77b29
Grab context response to visualize DAG
MadLittleMods Feb 2, 2021
2b2a53f
Proper test formatting
MadLittleMods Feb 3, 2021
975665d
Add m.historical to backfilled messages
MadLittleMods Feb 3, 2021
110352f
Add tests for behavior around m.historical
MadLittleMods Feb 3, 2021
8bbb929
Update docs
MadLittleMods Feb 5, 2021
22292b5
Remove docs already moved to #70
MadLittleMods Feb 5, 2021
3c332ba
Merge branch 'master' into eric/msc2716-backfilling-history
MadLittleMods Feb 9, 2021
1675fec
Enable msc2716 feature flag
MadLittleMods Feb 9, 2021
54061cb
Move SendEvent to the only test file it's used in
MadLittleMods Feb 10, 2021
3973312
Initial stab of defining AS in blueprint
MadLittleMods Feb 12, 2021
5a71989
More poking at defining app services
MadLittleMods Feb 13, 2021
c607f8d
More app service changes
MadLittleMods Feb 15, 2021
fe050a9
Passing registration by environment variable
MadLittleMods Feb 16, 2021
7625067
WIP: Make AS tokens available to use as users
MadLittleMods Feb 17, 2021
7d70586
Add hs domain to bridge MXID
MadLittleMods Feb 18, 2021
9292cf8
Copy AS registration to container instead of messy env variables
MadLittleMods Feb 22, 2021
4400459
Look for appservice registrations in the /appservices directory
MadLittleMods Feb 22, 2021
606eca3
Generate tokens on every run
MadLittleMods Feb 22, 2021
2a8ccf1
Refactor to use normalize func
MadLittleMods Feb 22, 2021
1dd26ef
Remove unused function
MadLittleMods Feb 22, 2021
4f96f44
Fix lint
MadLittleMods Feb 22, 2021
7f8c5c1
Revert some newline changes
MadLittleMods Feb 22, 2021
cf4d8e9
Add application service support to blueprints
MadLittleMods Feb 22, 2021
ee1ed9f
Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
MadLittleMods Feb 22, 2021
614c66e
Revert always showing logs
MadLittleMods Feb 22, 2021
ccb20e6
Revert always showing logs
MadLittleMods Feb 22, 2021
12e6ec0
Add comment doc
MadLittleMods Feb 22, 2021
0d1e9bf
Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
MadLittleMods Feb 22, 2021
1b19990
Some nits and remove the volume paths
MadLittleMods Feb 22, 2021
2d9c3b9
Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
MadLittleMods Feb 22, 2021
c1f07c2
Address review and add comment docs
MadLittleMods Feb 22, 2021
e08e8c8
Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
MadLittleMods Feb 22, 2021
2f78441
Refactor so our custom event type is contained within our MSC test file
MadLittleMods Feb 22, 2021
169a60d
Revert lint change already in other PR #73
MadLittleMods Feb 22, 2021
0dd18af
Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
MadLittleMods Feb 22, 2021
c6155af
Path escape AS IDs to avoid directory traversal attacks
kegsay Feb 23, 2021
be23da8
Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
MadLittleMods Feb 23, 2021
f353135
Merge branch 'master' into eric/msc2716-backfilling-history
MadLittleMods Feb 23, 2021
30b4f6a
Refactor tests to use variable amount of messages
MadLittleMods Feb 24, 2021
312feaa
Move test setup to the test itself
MadLittleMods Feb 24, 2021
923c41e
Add more messages to fill up sync and limit response
MadLittleMods Feb 24, 2021
63a59af
Add some better comments what we're actually doing and testing for
MadLittleMods Feb 24, 2021
172ecf2
Start of test that normal users can't backfill messages
MadLittleMods Feb 24, 2021
711ca3c
Proper message order using Synapse backfilled events and point all to…
MadLittleMods Mar 12, 2021
95b20af
Finish 403 forbidden for normal users trying to use ?prev_event
MadLittleMods Mar 15, 2021
dee8369
Add test around unknown prev event
MadLittleMods Mar 15, 2021
8978f58
Fix historical typo
MadLittleMods Mar 15, 2021
c5264d3
Work on backfilling history for a user who hasn't joined before
MadLittleMods Mar 16, 2021
16c50bb
Try to work with bulk send endpoint
MadLittleMods Mar 31, 2021
e8ca419
State test now passing after we just persist the event in Synapse and…
MadLittleMods Mar 31, 2021
bfc260e
Merge branch 'master' into eric/msc2716-backfilling-history
MadLittleMods Apr 14, 2021
6215726
Add better chunk identifiers
MadLittleMods Apr 14, 2021
367db56
Simplify JSON matcher for order or messages
MadLittleMods Apr 14, 2021
88b4e98
Update remaining tests to use new /bulksend
MadLittleMods Apr 15, 2021
90d8f7e
Test that historical messages can be federated
MadLittleMods Apr 22, 2021
ac8e770
Federation test debugging
MadLittleMods Apr 27, 2021
e1d203c
Log historical state events
MadLittleMods May 6, 2021
ec5fc15
Add tests to ensure historical messages are visible to federated user…
MadLittleMods May 6, 2021
7150004
Utilize chunk_id to connect to insertion points
MadLittleMods May 14, 2021
ed82752
Merge branch 'master' into eric/msc2716-backfilling-history
kegsay May 14, 2021
8d65ac7
Remove namespace
kegsay May 14, 2021
0145930
Add ?chunk_id query param to connect chunks
MadLittleMods May 27, 2021
37e086d
Merge branch 'eric/msc2716-backfilling-history' of github.com:matrix-…
MadLittleMods May 27, 2021
4c720f4
Add required type to register user from application service
MadLittleMods May 27, 2021
f970444
Also filter in insertion/marker events
MadLittleMods Jun 7, 2021
9ee5ad1
Switch from bulk to batch wording
MadLittleMods Jun 7, 2021
35c8f76
Use unstable endpoint for MSC2716 batch send
MadLittleMods Jun 17, 2021
3890321
Merge branch 'master' into eric/msc2716-backfilling-history
MadLittleMods Jun 21, 2021
007877f
Refactor to use functional client functions
MadLittleMods Jun 21, 2021
c03e49e
Fix blueprint name conflict
MadLittleMods Jun 21, 2021
3611002
Skip federation tests
MadLittleMods Jun 21, 2021
29582e5
Some cleanup
MadLittleMods Jun 21, 2021
603fd8f
Remove some unused bits
MadLittleMods Jun 25, 2021
b6b615d
Rename to eventIDs and better comments
MadLittleMods Jun 26, 2021
9a3da4e
Fix assertion when no events are returned and other nits
MadLittleMods Jun 28, 2021
dcd84ad
Re-use one test setup with sub-tests
MadLittleMods Jun 28, 2021
4875ef8
Revert "Re-use one test setup with sub-tests"
MadLittleMods Jun 28, 2021
e56c872
Add test for multiple senders within a single chunk
MadLittleMods Jun 30, 2021
d63fb7f
Make backfill vs batch less confusing
MadLittleMods Jul 7, 2021
34756a0
Use body bytes instead of reforming a stream buffer again
MadLittleMods Jul 7, 2021
3224030
Move comment to relevant test
MadLittleMods Jul 7, 2021
3ac2176
Backfill to batch send rename
MadLittleMods Jul 7, 2021
1d09b18
Make sure to register all virtual users
MadLittleMods Jul 9, 2021
9c68cb5
Add homeserver name to client request logging to differentiate who/where
MadLittleMods Jul 9, 2021
1f780ec
Allow subsequent joiners to be able to see the message history
MadLittleMods Jul 10, 2021
425206d
Some cleanup and improving federation tests
MadLittleMods Jul 14, 2021
53f5347
Add another test for pre-made insertion event
MadLittleMods Jul 14, 2021
991e91c
Make federation tests more robust
MadLittleMods Jul 15, 2021
0b0355b
Make chunk breakdown comment more clear
MadLittleMods Jul 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
[![Complement Dev](https://img.shields.io/matrix/complement:matrix.org.svg?label=%23complement%3Amatrix.org&logo=matrix&server_fqdn=matrix.org)](https://matrix.to/#/#complement:matrix.org)

### Complement

Complement is a black box integration testing framework for Matrix homeservers.


## adsf

To get started developing, see https://github.com/matrix-org/complement/blob/master/ONBOARDING.md

If you're looking to run Complement against a local dev instance of Synapse, see [`matrix-org/synapse` -> `scripts-dev/complement.sh`](https://github.com/matrix-org/synapse/blob/develop/scripts-dev/complement.sh)

If you want to develop Complement tests while working on a local dev instance of Synapse, edit `scripts-dev/complement.sh` to point to your local Complement checkout.


#### Running

You need to have Go and Docker installed. Then:
Expand Down
10 changes: 6 additions & 4 deletions internal/b/blueprints.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ type Room struct {
}

type Event struct {
Type string
Sender string
StateKey *string
Content map[string]interface{}
Type string
Sender string
OriginServerTS uint64
StateKey *string
PrevEvents []string
Content map[string]interface{}
// This field is ignored in blueprints as clients are unable to set it. Used with federation.Server
Unsigned map[string]interface{}
}
Expand Down
30 changes: 26 additions & 4 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,40 @@ func (c *CSAPI) JoinRoom(t *testing.T, roomIDOrAlias string, serverNames []strin
return GetJSONFieldStr(t, body, "room_id")
}

// SendEventSynced sends `e` into the room and waits for its event ID to come down /sync.
// Returns the event ID of the sent event.
func (c *CSAPI) SendEventSynced(t *testing.T, roomID string, e b.Event) string {
func (c *CSAPI) SendEvent(t *testing.T, roomID string, e b.Event) string {
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
t.Helper()
c.txnID++
paths := []string{"_matrix", "client", "r0", "rooms", roomID, "send", e.Type, strconv.Itoa(c.txnID)}
if e.StateKey != nil {
paths = []string{"_matrix", "client", "r0", "rooms", roomID, "state", e.Type, *e.StateKey}
}
res := c.MustDo(t, "PUT", paths, e.Content)

query := make(url.Values, len(e.PrevEvents))
for _, prevEvent := range e.PrevEvents {
query.Add("prev_event", prevEvent)
}
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved

if e.OriginServerTS != 0 {
query.Add("origin_server_ts", strconv.FormatUint(e.OriginServerTS, 10))
}
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved

b, err := json.Marshal(e.Content)
if err != nil {
t.Fatalf("CSAPI.Do failed to marshal JSON body: %s", err)
}

res := c.MustDoRaw(t, "PUT", paths, b, "application/json", query)
body := ParseJSON(t, res)
eventID := GetJSONFieldStr(t, body, "event_id")

return eventID
}

// SendEventSynced sends `e` into the room and waits for its event ID to come down /sync.
// Returns the event ID of the sent event.
func (c *CSAPI) SendEventSynced(t *testing.T, roomID string, e b.Event) string {
t.Helper()
eventID := c.SendEvent(t, roomID, e)
t.Logf("SendEventSynced waiting for event ID %s", eventID)
c.SyncUntilTimelineHas(t, roomID, func(r gjson.Result) bool {
return r.Get("event_id").Str == eventID
Expand Down
7 changes: 6 additions & 1 deletion internal/docker/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ type HomeserverDeployment struct {
// will print container logs before killing the container.
func (d *Deployment) Destroy(t *testing.T) {
t.Helper()
d.Deployer.Destroy(d, t.Failed())
d.Deployer.Destroy(
d,
// TODO: Revert this back to `t.Failed()`.
// I did this so I can always see the homersever logs regardless of outcome
true,
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
)
}

// Client returns a CSAPI client targeting the given hsName, using the access token for the given userID.
Expand Down
131 changes: 131 additions & 0 deletions tests/msc2716_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// +build msc2716

// This file contains tests for incrementally importing history to an existing room,
// a currently experimental feature defined by MSC2716, which you can read here:
// https://github.com/matrix-org/matrix-doc/pull/2716

package tests

import (
"net/url"
"testing"
"time"

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

// Test that the m.room.create and m.room.member events for a room we created comes down /sync
func TestBackfillingHistory(t *testing.T) {
deployment := Deploy(t, "rooms_state", b.BlueprintAlice)
defer deployment.Destroy(t)

userID := "@alice:hs1"
alice := deployment.Client(t, "hs1", userID)
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
roomID := alice.CreateRoom(t, struct{}{})

// eventA
eventA := alice.SendEventSynced(t, roomID, b.Event{
Type: "m.room.message",
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Message A",
},
})

insertTime := time.Now()
insertOriginServerTs := uint64(insertTime.UnixNano() / 1000000)

// wait 3ms to ensure that the timestamp changes enough intervals for each message we try to insert later
time.Sleep(3 * time.Millisecond)

// eventB
alice.SendEventSynced(t, roomID, b.Event{
Type: "m.room.message",
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Message B",
},
})
// eventC
alice.SendEventSynced(t, roomID, b.Event{
Type: "m.room.message",
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Message C",
},
})

// event1
event1 := alice.SendEvent(t, roomID, b.Event{
Type: "m.room.message",
PrevEvents: []string{
eventA,
},
OriginServerTS: insertOriginServerTs,
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Message 1",
},
})

// event2
event2 := alice.SendEvent(t, roomID, b.Event{
Type: "m.room.message",
PrevEvents: []string{
event1,
},
OriginServerTS: insertOriginServerTs + 1,
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Message 2",
},
})

// event3
alice.SendEvent(t, roomID, b.Event{
Type: "m.room.message",
PrevEvents: []string{
event2,
},
OriginServerTS: insertOriginServerTs + 2,
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Message 3",
},
})

res := alice.MustDoRaw(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, nil, "application/json", url.Values{
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
"dir": []string{"b"},
"limit": []string{"100"},
})

t.Logf("aweawfeefwaweafeafw")
body := client.ParseJSON(t, res)
logrus.WithFields(logrus.Fields{
"insertOriginServerTs": insertOriginServerTs,
"res": res,
"body": string(body),
}).Error("messages res")

t.Run("parallel", func(t *testing.T) {
// sytest: Room creation reports m.room.create to myself
t.Run("Room creation reports m.room.create to myself", func(t *testing.T) {
t.Parallel()

alice := deployment.Client(t, "hs1", userID)

alice.SyncUntilTimelineHas(t, roomID, func(ev gjson.Result) bool {
if ev.Get("type").Str != "m.room.create" {
return false
}
must.EqualStr(t, ev.Get("sender").Str, userID, "wrong sender")
must.EqualStr(t, ev.Get("content").Get("creator").Str, userID, "wrong content.creator")
return true
})
})
})
}