- 
                Notifications
    You must be signed in to change notification settings 
- Fork 60
Add tests for MSC2716 and backfilling history #68
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
          
     Merged
      
      
    
  
     Merged
                    Changes from 9 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 55c5a8c
              
                Allow SendEventSynced to pass over prev_event querystring parameters
              
              
                MadLittleMods 70036ac
              
                Switch to fire and forget sending over historical events which we don…
              
              
                MadLittleMods dabdf5a
              
                Override origin_server_ts
              
              
                MadLittleMods 6b77b29
              
                Grab context response to visualize DAG
              
              
                MadLittleMods 2b2a53f
              
                Proper test formatting
              
              
                MadLittleMods 975665d
              
                Add m.historical to backfilled messages
              
              
                MadLittleMods 110352f
              
                Add tests for behavior around m.historical
              
              
                MadLittleMods 8bbb929
              
                Update docs
              
              
                MadLittleMods 22292b5
              
                Remove docs already moved to #70
              
              
                MadLittleMods 3c332ba
              
                Merge branch 'master' into eric/msc2716-backfilling-history
              
              
                MadLittleMods 1675fec
              
                Enable msc2716 feature flag
              
              
                MadLittleMods 54061cb
              
                Move SendEvent to the only test file it's used in
              
              
                MadLittleMods 3973312
              
                Initial stab of defining AS in blueprint
              
              
                MadLittleMods 5a71989
              
                More poking at defining app services
              
              
                MadLittleMods c607f8d
              
                More app service changes
              
              
                MadLittleMods fe050a9
              
                Passing registration by environment variable
              
              
                MadLittleMods 7625067
              
                WIP: Make AS tokens available to use as users
              
              
                MadLittleMods 7d70586
              
                Add hs domain to bridge MXID
              
              
                MadLittleMods 9292cf8
              
                Copy AS registration to container instead of messy env variables
              
              
                MadLittleMods 4400459
              
                Look for appservice registrations in the /appservices directory
              
              
                MadLittleMods 606eca3
              
                Generate tokens on every run
              
              
                MadLittleMods 2a8ccf1
              
                Refactor to use normalize func
              
              
                MadLittleMods 1dd26ef
              
                Remove unused function
              
              
                MadLittleMods 4f96f44
              
                Fix lint
              
              
                MadLittleMods 7f8c5c1
              
                Revert some newline changes
              
              
                MadLittleMods cf4d8e9
              
                Add application service support to blueprints
              
              
                MadLittleMods ee1ed9f
              
                Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
              
              
                MadLittleMods 614c66e
              
                Revert always showing logs
              
              
                MadLittleMods ccb20e6
              
                Revert always showing logs
              
              
                MadLittleMods 12e6ec0
              
                Add comment doc
              
              
                MadLittleMods 0d1e9bf
              
                Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
              
              
                MadLittleMods 1b19990
              
                Some nits and remove the volume paths
              
              
                MadLittleMods 2d9c3b9
              
                Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
              
              
                MadLittleMods c1f07c2
              
                Address review and add comment docs
              
              
                MadLittleMods e08e8c8
              
                Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
              
              
                MadLittleMods 2f78441
              
                Refactor so our custom event type is contained within our MSC test file
              
              
                MadLittleMods 169a60d
              
                Revert lint change already in other PR #73
              
              
                MadLittleMods 0dd18af
              
                Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
              
              
                MadLittleMods c6155af
              
                Path escape AS IDs to avoid directory traversal attacks
              
              
                kegsay be23da8
              
                Merge branch 'eric/appservice-support' into eric/msc2716-backfilling-…
              
              
                MadLittleMods f353135
              
                Merge branch 'master' into eric/msc2716-backfilling-history
              
              
                MadLittleMods 30b4f6a
              
                Refactor tests to use variable amount of messages
              
              
                MadLittleMods 312feaa
              
                Move test setup to the test itself
              
              
                MadLittleMods 923c41e
              
                Add more messages to fill up sync and limit response
              
              
                MadLittleMods 63a59af
              
                Add some better comments what we're actually doing and testing for
              
              
                MadLittleMods 172ecf2
              
                Start of test that normal users can't backfill messages
              
              
                MadLittleMods 711ca3c
              
                Proper message order using Synapse backfilled events and point all to…
              
              
                MadLittleMods 95b20af
              
                Finish 403 forbidden for normal users trying to use ?prev_event
              
              
                MadLittleMods dee8369
              
                Add test around unknown prev event
              
              
                MadLittleMods 8978f58
              
                Fix historical typo
              
              
                MadLittleMods c5264d3
              
                Work on backfilling history for a user who hasn't joined before
              
              
                MadLittleMods 16c50bb
              
                Try to work with bulk send endpoint
              
              
                MadLittleMods e8ca419
              
                State test now passing after we just persist the event in Synapse and…
              
              
                MadLittleMods bfc260e
              
                Merge branch 'master' into eric/msc2716-backfilling-history
              
              
                MadLittleMods 6215726
              
                Add better chunk identifiers
              
              
                MadLittleMods 367db56
              
                Simplify JSON matcher for order or messages
              
              
                MadLittleMods 88b4e98
              
                Update remaining tests to use new /bulksend
              
              
                MadLittleMods 90d8f7e
              
                Test that historical messages can be federated
              
              
                MadLittleMods ac8e770
              
                Federation test debugging
              
              
                MadLittleMods e1d203c
              
                Log historical state events
              
              
                MadLittleMods ec5fc15
              
                Add tests to ensure historical messages are visible to federated user…
              
              
                MadLittleMods 7150004
              
                Utilize chunk_id to connect to insertion points
              
              
                MadLittleMods ed82752
              
                Merge branch 'master' into eric/msc2716-backfilling-history
              
              
                kegsay 8d65ac7
              
                Remove namespace
              
              
                kegsay 0145930
              
                Add ?chunk_id query param to connect chunks
              
              
                MadLittleMods 37e086d
              
                Merge branch 'eric/msc2716-backfilling-history' of github.com:matrix-…
              
              
                MadLittleMods 4c720f4
              
                Add required type to register user from application service
              
              
                MadLittleMods f970444
              
                Also filter in insertion/marker events
              
              
                MadLittleMods 9ee5ad1
              
                Switch from bulk to batch wording
              
              
                MadLittleMods 35c8f76
              
                Use unstable endpoint for MSC2716 batch send
              
              
                MadLittleMods 3890321
              
                Merge branch 'master' into eric/msc2716-backfilling-history
              
              
                MadLittleMods 007877f
              
                Refactor to use functional client functions
              
              
                MadLittleMods c03e49e
              
                Fix blueprint name conflict
              
              
                MadLittleMods 3611002
              
                Skip federation tests
              
              
                MadLittleMods 29582e5
              
                Some cleanup
              
              
                MadLittleMods 603fd8f
              
                Remove some unused bits
              
              
                MadLittleMods b6b615d
              
                Rename to eventIDs and better comments
              
              
                MadLittleMods 9a3da4e
              
                Fix assertion when no events are returned and other nits
              
              
                MadLittleMods dcd84ad
              
                Re-use one test setup with sub-tests
              
              
                MadLittleMods 4875ef8
              
                Revert "Re-use one test setup with sub-tests"
              
              
                MadLittleMods e56c872
              
                Add test for multiple senders within a single chunk
              
              
                MadLittleMods d63fb7f
              
                Make backfill vs batch less confusing
              
              
                MadLittleMods 34756a0
              
                Use body bytes instead of reforming a stream buffer again
              
              
                MadLittleMods 3224030
              
                Move comment to relevant test
              
              
                MadLittleMods 3ac2176
              
                Backfill to batch send rename
              
              
                MadLittleMods 1d09b18
              
                Make sure to register all virtual users
              
              
                MadLittleMods 9c68cb5
              
                Add homeserver name to client request logging to differentiate who/where
              
              
                MadLittleMods 1f780ec
              
                Allow subsequent joiners to be able to see the  message history
              
              
                MadLittleMods 425206d
              
                Some cleanup and improving federation tests
              
              
                MadLittleMods 53f5347
              
                Add another test for pre-made insertion event
              
              
                MadLittleMods 991e91c
              
                Make federation tests more robust
              
              
                MadLittleMods 0b0355b
              
                Make chunk breakdown comment more clear
              
              
                MadLittleMods File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| // +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 ( | ||
| "fmt" | ||
| "net/url" | ||
| "testing" | ||
| "time" | ||
|  | ||
| "github.com/matrix-org/complement/internal/b" | ||
| "github.com/matrix-org/complement/internal/client" | ||
| "github.com/matrix-org/complement/internal/match" | ||
| "github.com/matrix-org/complement/internal/must" | ||
| "github.com/tidwall/gjson" | ||
| ) | ||
|  | ||
| // Test that the message events we insert between A and B come back in the correct order from /messages | ||
| 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, eventB, eventC, timeAfterEventA := createMessagesInRoom(t, alice, roomID) | ||
|  | ||
| event1, event2, event3 := backfillMessagesAtTime(t, alice, roomID, eventA, timeAfterEventA) | ||
|  | ||
| // eventStar | ||
| eventStar := alice.SendEventSynced(t, roomID, b.Event{ | ||
| Type: "m.room.message", | ||
| Content: map[string]interface{}{ | ||
| "msgtype": "m.text", | ||
| "body": "Message *", | ||
| }, | ||
| }) | ||
|  | ||
| t.Run("parallel", func(t *testing.T) { | ||
| t.Run("Backfilled messages come back in correct order", func(t *testing.T) { | ||
| t.Parallel() | ||
|  | ||
| messagesRes := alice.MustDoRaw(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, nil, "application/json", url.Values{ | ||
| "dir": []string{"b"}, | ||
| "limit": []string{"100"}, | ||
| }) | ||
|  | ||
| expectedMessageOrder := []string{ | ||
| eventStar, eventC, eventB, event3, event2, event1, eventA, | ||
| } | ||
|  | ||
| must.MatchResponse(t, messagesRes, match.HTTPResponse{ | ||
| JSON: []match.JSON{ | ||
| match.JSONArrayEach("chunk", func(r gjson.Result) error { | ||
|         
                  MadLittleMods marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| // Find all events in order | ||
| if len(r.Get("content").Get("body").Str) > 0 { | ||
| // Pop the next message off the expected list | ||
| nextEventInOrder := expectedMessageOrder[0] | ||
| expectedMessageOrder = expectedMessageOrder[1:] | ||
|  | ||
| if r.Get("event_id").Str != nextEventInOrder { | ||
| return fmt.Errorf("Next event found was %s but expected %s", r.Get("event_id").Str, nextEventInOrder) | ||
| } | ||
| } | ||
|  | ||
| return nil | ||
| }), | ||
| }, | ||
| }) | ||
| }) | ||
|  | ||
| t.Run("Backfilled events with m.historical do not come down /sync", func(t *testing.T) { | ||
| t.Parallel() | ||
|  | ||
| roomID := alice.CreateRoom(t, struct{}{}) | ||
| eventA, _, _, timeAfterEventA := createMessagesInRoom(t, alice, roomID) | ||
| insertOriginServerTs := uint64(timeAfterEventA.UnixNano() / 1000000) | ||
|  | ||
| // If we see this message in the /sync, then something went wrong | ||
| 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", | ||
| "m.historical": true, | ||
| }, | ||
| }) | ||
|  | ||
| // This is just a dummy event we search for after event1 | ||
| eventStar := alice.SendEvent(t, roomID, b.Event{ | ||
| Type: "m.room.message", | ||
| Content: map[string]interface{}{ | ||
| "msgtype": "m.text", | ||
| "body": "Message *", | ||
| }, | ||
| }) | ||
|  | ||
| // Sync until we find the star message. If we're able to see the star message | ||
| // that occurs after event1 without seeing event1 in the mean-time, I think we're safe to | ||
| // assume it won't sync | ||
| alice.SyncUntil(t, "", "rooms.join."+client.GjsonEscape(roomID)+".timeline.events", func(r gjson.Result) bool { | ||
|         
                  MadLittleMods marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| if r.Get("event_id").Str == event1 { | ||
| t.Fatalf("We should not see the %s event in /sync response but it was present", event1) | ||
| } | ||
|  | ||
| return r.Get("event_id").Str == eventStar | ||
| }) | ||
| }) | ||
|  | ||
| t.Run("Backfilled events without m.historical come down /sync", func(t *testing.T) { | ||
| t.Parallel() | ||
|  | ||
| roomID := alice.CreateRoom(t, struct{}{}) | ||
| eventA, _, _, timeAfterEventA := createMessagesInRoom(t, alice, roomID) | ||
| insertOriginServerTs := uint64(timeAfterEventA.UnixNano() / 1000000) | ||
|  | ||
| alice.SendEventSynced(t, roomID, b.Event{ | ||
| Type: "m.room.message", | ||
| PrevEvents: []string{ | ||
| eventA, | ||
| }, | ||
| OriginServerTS: insertOriginServerTs, | ||
| Content: map[string]interface{}{ | ||
| "msgtype": "m.text", | ||
| "body": "Message 1", | ||
| }, | ||
| }) | ||
|         
                  MadLittleMods marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }) | ||
| }) | ||
| } | ||
|  | ||
| func createMessagesInRoom(t *testing.T, c *client.CSAPI, roomID string) (string, string, string, time.Time) { | ||
| // eventA | ||
| eventA := c.SendEventSynced(t, roomID, b.Event{ | ||
| Type: "m.room.message", | ||
| Content: map[string]interface{}{ | ||
| "msgtype": "m.text", | ||
| "body": "Message A", | ||
| }, | ||
| }) | ||
|  | ||
| timeAfterEventA := time.Now() | ||
|  | ||
| // wait 3ms to ensure that the timestamp changes enough for each of the 3 message we try to insert later | ||
| time.Sleep(3 * time.Millisecond) | ||
|  | ||
| // eventB | ||
| eventB := c.SendEventSynced(t, roomID, b.Event{ | ||
| Type: "m.room.message", | ||
| Content: map[string]interface{}{ | ||
| "msgtype": "m.text", | ||
| "body": "Message B", | ||
| }, | ||
| }) | ||
| // eventC | ||
| eventC := c.SendEventSynced(t, roomID, b.Event{ | ||
| Type: "m.room.message", | ||
| Content: map[string]interface{}{ | ||
| "msgtype": "m.text", | ||
| "body": "Message C", | ||
| }, | ||
| }) | ||
|  | ||
| return eventA, eventB, eventC, timeAfterEventA | ||
| } | ||
|  | ||
| func backfillMessagesAtTime(t *testing.T, c *client.CSAPI, roomID string, insertAfterEvent string, insertTime time.Time) (string, string, string) { | ||
| insertOriginServerTs := uint64(insertTime.UnixNano() / 1000000) | ||
|  | ||
| // event1 | ||
| event1 := c.SendEvent(t, roomID, b.Event{ | ||
| Type: "m.room.message", | ||
| PrevEvents: []string{ | ||
| insertAfterEvent, | ||
| }, | ||
| OriginServerTS: insertOriginServerTs, | ||
| Content: map[string]interface{}{ | ||
| "msgtype": "m.text", | ||
| "body": "Message 1", | ||
| "m.historical": true, | ||
| }, | ||
| }) | ||
|  | ||
| // event2 | ||
| event2 := c.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", | ||
| "m.historical": true, | ||
| }, | ||
| }) | ||
|  | ||
| // event3 | ||
| event3 := c.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", | ||
| "m.historical": true, | ||
| }, | ||
| }) | ||
|  | ||
| return event1, event2, event3 | ||
| } | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.