-
Notifications
You must be signed in to change notification settings - Fork 39
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 timestamp
to room responses
#247
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
926f1c5
Add timestamp to room responses
S7evinK 36ca09e
Add e2e tests for room timestamps
S7evinK de4fa34
Add more tests, comments, don't leak timestamps
S7evinK 778c6cd
Typo..
S7evinK dd243f1
Don't panic if tehre is no roomListsMeta
S7evinK 3857e67
Try that again
S7evinK 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 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 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 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 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,166 @@ | ||
package syncv3_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/matrix-org/sliding-sync/sync3" | ||
"github.com/matrix-org/sliding-sync/testutils/m" | ||
) | ||
|
||
func TestTimestamp(t *testing.T) { | ||
alice := registerNewUser(t) | ||
bob := registerNewUser(t) | ||
charlie := registerNewUser(t) | ||
|
||
roomID := alice.CreateRoom(t, map[string]interface{}{ | ||
"preset": "public_chat", | ||
}) | ||
|
||
var gotTs, expectedTs uint64 | ||
|
||
lists := map[string]sync3.RequestList{ | ||
"myFirstList": { | ||
Ranges: [][2]int64{{0, 1}}, | ||
RoomSubscription: sync3.RoomSubscription{ | ||
TimelineLimit: 10, | ||
}, | ||
BumpEventTypes: []string{"m.room.message"}, // only messages bump the timestamp | ||
}, | ||
"mySecondList": { | ||
Ranges: [][2]int64{{0, 1}}, | ||
RoomSubscription: sync3.RoomSubscription{ | ||
TimelineLimit: 10, | ||
}, | ||
BumpEventTypes: []string{"m.reaction"}, // only reactions bump the timestamp | ||
}, | ||
} | ||
|
||
// Init sync to get the latest timestamp | ||
resAlice := alice.SlidingSync(t, sync3.Request{ | ||
RoomSubscriptions: map[string]sync3.RoomSubscription{ | ||
roomID: { | ||
TimelineLimit: 10, | ||
}, | ||
}, | ||
}) | ||
m.MatchResponse(t, resAlice, m.MatchRoomSubscription(roomID, m.MatchRoomInitial(true))) | ||
timestampBeforeBobJoined := resAlice.Rooms[roomID].Timestamp | ||
|
||
bob.JoinRoom(t, roomID, nil) | ||
resAlice = alice.SlidingSyncUntilMembership(t, resAlice.Pos, roomID, bob, "join") | ||
resBob := bob.SlidingSync(t, sync3.Request{ | ||
Lists: lists, | ||
}) | ||
|
||
// Bob should see a different timestamp than alice, as he just joined | ||
gotTs = resBob.Rooms[roomID].Timestamp | ||
expectedTs = resAlice.Rooms[roomID].Timestamp | ||
if gotTs != expectedTs { | ||
t.Fatalf("expected timestamp to be equal, but got: %v vs %v", gotTs, expectedTs) | ||
} | ||
// ... the timestamp should still differ from what Alice received before the join | ||
if gotTs == timestampBeforeBobJoined { | ||
t.Fatalf("expected timestamp to differ, but got: %v vs %v", gotTs, timestampBeforeBobJoined) | ||
} | ||
|
||
// Send an event which should NOT bump Bobs timestamp, because it is not listed it | ||
// any BumpEventTypes | ||
emptyStateKey := "" | ||
eventID := alice.SendEventSynced(t, roomID, Event{ | ||
Type: "m.room.topic", | ||
StateKey: &emptyStateKey, | ||
Content: map[string]interface{}{ | ||
"topic": "random topic", | ||
}, | ||
}) | ||
time.Sleep(time.Millisecond) | ||
|
||
resBob = bob.SlidingSyncUntilEventID(t, resBob.Pos, roomID, eventID) | ||
gotTs = resBob.Rooms[roomID].Timestamp | ||
expectedTs = resAlice.Rooms[roomID].Timestamp | ||
if gotTs != expectedTs { | ||
t.Fatalf("expected timestamps to be the same, but they aren't: %v vs %v", gotTs, expectedTs) | ||
} | ||
expectedTs = gotTs | ||
|
||
// Now send a message which bumps the timestamp in myFirstList | ||
eventID = alice.SendEventSynced(t, roomID, Event{ | ||
Type: "m.room.message", | ||
Content: map[string]interface{}{ | ||
"msgtype": "m.text", | ||
"body": "Hello, world!", | ||
}, | ||
}) | ||
time.Sleep(time.Millisecond) | ||
|
||
resBob = bob.SlidingSyncUntilEventID(t, resBob.Pos, roomID, eventID) | ||
gotTs = resBob.Rooms[roomID].Timestamp | ||
if expectedTs == gotTs { | ||
t.Fatalf("expected timestamps to be different, but they aren't: %v vs %v", gotTs, expectedTs) | ||
} | ||
expectedTs = gotTs | ||
|
||
// Now send a message which bumps the timestamp in mySecondList | ||
eventID = alice.SendEventSynced(t, roomID, Event{ | ||
Type: "m.reaction", | ||
Content: map[string]interface{}{ | ||
"m.relates.to": map[string]interface{}{ | ||
"event_id": eventID, | ||
"key": "✅", | ||
"rel_type": "m.annotation", | ||
}, | ||
}, | ||
}) | ||
time.Sleep(time.Millisecond) | ||
|
||
resBob = bob.SlidingSyncUntilEventID(t, resBob.Pos, roomID, eventID) | ||
bobTimestampReaction := resBob.Rooms[roomID].Timestamp | ||
if bobTimestampReaction == expectedTs { | ||
t.Fatalf("expected timestamps to be different, but they aren't: %v vs %v", expectedTs, bobTimestampReaction) | ||
} | ||
expectedTs = bobTimestampReaction | ||
|
||
// Send another event which should NOT bump Bobs timestamp | ||
eventID = alice.SendEventSynced(t, roomID, Event{ | ||
Type: "m.room.name", | ||
StateKey: &emptyStateKey, | ||
Content: map[string]interface{}{ | ||
"name": "random name", | ||
}, | ||
}) | ||
time.Sleep(time.Millisecond) | ||
|
||
resBob = bob.SlidingSyncUntilEventID(t, resBob.Pos, roomID, eventID) | ||
gotTs = resBob.Rooms[roomID].Timestamp | ||
if gotTs != expectedTs { | ||
t.Fatalf("expected timestamps to be the same, but they aren't: %v, expected %v", gotTs, expectedTs) | ||
} | ||
|
||
// Bob makes an initial sync again, he should still see the m.reaction timestamp | ||
resBob = bob.SlidingSync(t, sync3.Request{ | ||
Lists: lists, | ||
}) | ||
|
||
gotTs = resBob.Rooms[roomID].Timestamp | ||
expectedTs = bobTimestampReaction | ||
if gotTs != expectedTs { | ||
t.Fatalf("initial sync contains wrong timestamp: %d, expected %d", gotTs, expectedTs) | ||
} | ||
|
||
// Charlie joins the room | ||
charlie.JoinRoom(t, roomID, nil) | ||
resAlice = alice.SlidingSyncUntilMembership(t, resAlice.Pos, roomID, charlie, "join") | ||
|
||
resCharlie := charlie.SlidingSync(t, sync3.Request{ | ||
Lists: lists, | ||
}) | ||
|
||
// Charlie just joined so should see the same timestamp as Alice, even if | ||
// Charlie has the same bumpEvents as Bob, we don't leak those timestamps. | ||
gotTs = resCharlie.Rooms[roomID].Timestamp | ||
expectedTs = resAlice.Rooms[roomID].Timestamp | ||
if gotTs != expectedTs { | ||
t.Fatalf("Charlie should see the timestamp they joined, but didn't: %d, expected %d", gotTs, expectedTs) | ||
} | ||
} | ||
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.
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.
Needs more tests. Specifically:
time.Sleep(time.Millisecond)
after each send to ensure that timestamps will change.