Skip to content

Commit

Permalink
Override origin_server_ts
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Jan 30, 2021
1 parent 70036ac commit dabdf5a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
11 changes: 6 additions & 5 deletions internal/b/blueprints.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ type Room struct {
}

type Event struct {
Type string
Sender string
StateKey *string
PrevEvents []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
4 changes: 4 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func (c *CSAPI) SendEvent(t *testing.T, roomID string, e b.Event) string {
query.Add("prev_event", prevEvent)
}

if e.OriginServerTS != 0 {
query.Add("origin_server_ts", strconv.FormatUint(e.OriginServerTS, 10))
}

b, err := json.Marshal(e.Content)
if err != nil {
t.Fatalf("CSAPI.Do failed to marshal JSON body: %s", err)
Expand Down
17 changes: 16 additions & 1 deletion tests/msc2716_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ 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"
Expand All @@ -33,6 +35,13 @@ func TestBackfillingHistory(t *testing.T) {
"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",
Expand All @@ -56,6 +65,7 @@ func TestBackfillingHistory(t *testing.T) {
PrevEvents: []string{
eventA,
},
OriginServerTS: insertOriginServerTs,
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Message 1",
Expand All @@ -68,6 +78,7 @@ func TestBackfillingHistory(t *testing.T) {
PrevEvents: []string{
event1,
},
OriginServerTS: insertOriginServerTs + 1,
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Message 2",
Expand All @@ -80,6 +91,7 @@ func TestBackfillingHistory(t *testing.T) {
PrevEvents: []string{
event2,
},
OriginServerTS: insertOriginServerTs + 2,
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Message 3",
Expand All @@ -92,8 +104,11 @@ func TestBackfillingHistory(t *testing.T) {
})

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

t.Run("parallel", func(t *testing.T) {
Expand Down

0 comments on commit dabdf5a

Please sign in to comment.