-
Notifications
You must be signed in to change notification settings - Fork 52
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
Draft: Make sure historical state events don't come down /transactions
for application services (MSC2716)
#221
Changes from 2 commits
6c1f6a0
eeb5076
865848d
7ab71d4
06935a7
4268459
c40bdf1
d920d70
7ce9749
4e00b9f
12ef80b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,7 +255,7 @@ func TestImportHistoricalMessages(t *testing.T) { | |
}) | ||
}) | ||
|
||
t.Run("Historical events from /batch_send do not come down in an incremental sync", func(t *testing.T) { | ||
t.Run("Historical events from batch_send do not come down in an incremental sync", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
roomID := as.CreateRoom(t, createPublicRoomOpts) | ||
|
@@ -269,6 +269,10 @@ func TestImportHistoricalMessages(t *testing.T) { | |
// Create some "live" events to saturate and fill up the /sync response | ||
createMessagesInRoom(t, alice, roomID, 5) | ||
|
||
// Get a /sync `since` pagination token we can try paginating from later | ||
// on | ||
since := doInitialSync(t, alice) | ||
|
||
// Import a historical event | ||
batchSendRes := batchSendHistoricalMessages( | ||
t, | ||
|
@@ -283,19 +287,20 @@ func TestImportHistoricalMessages(t *testing.T) { | |
) | ||
batchSendResBody := client.ParseJSON(t, batchSendRes) | ||
historicalEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "event_ids") | ||
historicalEventId := historicalEventIDs[0] | ||
historicalStateEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "state_event_ids") | ||
|
||
// This is just a dummy event we search for after the historicalEventId | ||
// This is just a dummy event we search for after the historicalEventIDs/historicalStateEventIDs | ||
eventIDsAfterHistoricalImport := createMessagesInRoom(t, alice, roomID, 1) | ||
eventIDAfterHistoricalImport := eventIDsAfterHistoricalImport[0] | ||
|
||
// Sync until we find the eventIDAfterHistoricalImport. | ||
// If we're able to see the eventIDAfterHistoricalImport that occurs after | ||
// the historicalEventId without seeing eventIDAfterHistoricalImport in | ||
// between, we're probably safe to assume it won't sync | ||
alice.SyncUntil(t, "", `{ "room": { "timeline": { "limit": 3 } } }`, "rooms.join."+client.GjsonEscape(roomID)+".timeline.events", func(r gjson.Result) bool { | ||
if r.Get("event_id").Str == historicalEventId { | ||
t.Fatalf("We should not see the %s historical event in /sync response but it was present", historicalEventId) | ||
// Sync from before we did any batch sending until we find the | ||
// eventIDAfterHistoricalImport. If we're able to see | ||
// eventIDAfterHistoricalImport without any the | ||
// historicalEventIDs/historicalStateEventIDs in between, we're probably | ||
// safe to assume it won't sync. | ||
alice.SyncUntil(t, since, "", "rooms.join."+client.GjsonEscape(roomID)+".timeline.events", func(r gjson.Result) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made this test more clear on what's happening. We now paginate sync from before we |
||
if includes(r.Get("event_id").Str, historicalEventIDs) || includes(r.Get("event_id").Str, historicalStateEventIDs) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is where we additionally check for the |
||
t.Fatalf("We should not see the %s historical event in /sync response but it was present", r.Get("event_id").Str) | ||
} | ||
|
||
return r.Get("event_id").Str == eventIDAfterHistoricalImport | ||
|
@@ -926,6 +931,16 @@ func reversed(in []string) []string { | |
return out | ||
} | ||
|
||
func includes(needle string, haystack []string) bool { | ||
for _, item := range haystack { | ||
if needle == item { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
func fetchUntilMessagesResponseHas(t *testing.T, c *client.CSAPI, roomID string, check func(gjson.Result) bool) { | ||
t.Helper() | ||
start := time.Now() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the
/
in the test name so I can actually run it individually,COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestImportHistoricalMessages/parallel/Historical_events_from_batch_send_do_not_come_down_in_an_incremental_sync
See https://gist.github.com/MadLittleMods/4ab08f51609fab759247f299a4e33406 for why there is a problem using a
/
to match a single test.