forked from matrix-org/sliding-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvite_test.go
140 lines (127 loc) · 3.77 KB
/
invite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package syncv3
import (
"testing"
"time"
"github.com/matrix-org/sliding-sync/sync2"
"github.com/matrix-org/sliding-sync/sync3"
"github.com/matrix-org/sliding-sync/testutils"
"github.com/matrix-org/sliding-sync/testutils/m"
)
func TestStuckInvites(t *testing.T) {
boolTrue := true
// setup code
pqString := testutils.PrepareDBConnectionString()
v2 := runTestV2Server(t)
v3 := runTestServer(t, v2, pqString)
defer v2.close()
defer v3.close()
preSyncInviteRoomID := "!pre:localhost"
postSyncInviteRoomID := "!post:localhost"
inviteState := createRoomState(t, bob, time.Now())
inviteState = append(inviteState, testutils.NewStateEvent(t, "m.room.member", alice, bob, map[string]interface{}{
"membership": "invite",
}))
v2.addAccount(t, alice, aliceToken)
v2.queueResponse(alice, sync2.SyncResponse{
Rooms: sync2.SyncRoomsResponse{
Invite: map[string]sync2.SyncV2InviteResponse{
preSyncInviteRoomID: {
InviteState: sync2.EventsResponse{
Events: inviteState,
},
},
},
},
})
// initial sync, should see the invite
res := v3.mustDoV3Request(t, aliceToken, sync3.Request{
Lists: map[string]sync3.RequestList{
"a": {
Ranges: sync3.SliceRanges{{0, 10}},
Filters: &sync3.RequestFilters{
IsInvite: &boolTrue,
},
},
},
})
m.MatchResponse(t, res, m.MatchList("a", m.MatchV3Count(1), m.MatchV3Ops(
m.MatchV3SyncOp(0, 0, []string{preSyncInviteRoomID}),
)))
// live stream invite
inviteState2 := createRoomState(t, bob, time.Now())
inviteState2 = append(inviteState2, testutils.NewStateEvent(t, "m.room.member", alice, bob, map[string]interface{}{
"membership": "invite",
}))
v2.queueResponse(alice, sync2.SyncResponse{
Rooms: sync2.SyncRoomsResponse{
Invite: map[string]sync2.SyncV2InviteResponse{
postSyncInviteRoomID: {
InviteState: sync2.EventsResponse{
Events: inviteState2,
},
},
},
},
})
v2.waitUntilEmpty(t, alice)
res = v3.mustDoV3RequestWithPos(t, aliceToken, res.Pos, sync3.Request{
Lists: map[string]sync3.RequestList{
"a": {
Ranges: sync3.SliceRanges{{0, 10}},
},
},
})
m.MatchResponse(t, res, m.MatchList("a", m.MatchV3Count(2), m.MatchV3Ops(
m.MatchV3DeleteOp(1),
m.MatchV3InsertOp(0, postSyncInviteRoomID),
)))
// accept both invites: replace the invite (last state event)
inviteState[len(inviteState)-1] = testutils.NewJoinEvent(t, alice, testutils.WithUnsigned(map[string]interface{}{
"prev_content": map[string]string{
"membership": "invite",
},
}))
inviteState2[len(inviteState2)-1] = testutils.NewJoinEvent(t, alice, testutils.WithUnsigned(map[string]interface{}{
"prev_content": map[string]string{
"membership": "invite",
},
}))
v2.queueResponse(alice, sync2.SyncResponse{
Rooms: sync2.SyncRoomsResponse{
Join: v2JoinTimeline(roomEvents{
roomID: preSyncInviteRoomID,
events: inviteState,
},
roomEvents{
roomID: postSyncInviteRoomID,
events: inviteState2,
}),
},
})
v2.waitUntilEmpty(t, alice)
// the entries are removed
res = v3.mustDoV3RequestWithPos(t, aliceToken, res.Pos, sync3.Request{
Lists: map[string]sync3.RequestList{
"a": {
Ranges: sync3.SliceRanges{{0, 10}},
},
},
})
// not asserting the ops here as they could be DELETE 1, DELETE 0 or DELETE 0, DELETE 0 which is hard
// to assert.
m.MatchResponse(t, res, m.MatchList("a", m.MatchV3Count(0)))
// restart the server
v3.restart(t, v2, pqString)
// now query for invites: there should be none if we are clearing the DB correctly.
res = v3.mustDoV3Request(t, aliceToken, sync3.Request{
Lists: map[string]sync3.RequestList{
"a": {
Ranges: sync3.SliceRanges{{0, 10}},
Filters: &sync3.RequestFilters{
IsInvite: &boolTrue,
},
},
},
})
m.MatchResponse(t, res, m.MatchNoV3Ops(), m.MatchRoomSubscriptionsStrict(nil))
}