Skip to content

Commit

Permalink
Add tests for MSC2716 and backfilling history
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Jan 28, 2021
1 parent df15003 commit 15ba451
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 4 deletions.
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
9 changes: 5 additions & 4 deletions internal/b/blueprints.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ type Room struct {
}

type Event struct {
Type string
Sender string
StateKey *string
Content map[string]interface{}
Type string
Sender string
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
78 changes: 78 additions & 0 deletions tests/msc2716_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// +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 (
"testing"

"github.com/matrix-org/complement/internal/b"
"github.com/matrix-org/complement/internal/must"
"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)
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",
},
})
// 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
alice.SendEventSynced(t, roomID, b.Event{
Type: "m.room.message",
PrevEvents: []string{
eventA,
},
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Message 1",
},
})

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
})
})
})
}

0 comments on commit 15ba451

Please sign in to comment.