forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
participantsource_test.go
97 lines (88 loc) · 2.7 KB
/
participantsource_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
package chat
import (
"context"
"testing"
"time"
"github.com/keybase/client/go/chat/types"
"github.com/keybase/client/go/chat/utils"
"github.com/keybase/client/go/protocol/chat1"
"github.com/keybase/client/go/protocol/gregor1"
"github.com/keybase/client/go/teams"
"github.com/stretchr/testify/require"
)
func TestParticipantsSource(t *testing.T) {
useRemoteMock = false
defer func() { useRemoteMock = true }()
ctc := makeChatTestContext(t, "TestParticipantsSource", 3)
defer ctc.cleanup()
timeout := time.Second * 20
users := ctc.users()
tc := ctc.world.Tcs[users[0].Username]
ctx := ctc.as(t, users[0]).startCtx
uid := gregor1.UID(users[0].GetUID().ToBytes())
listener0 := newServerChatListener()
ctc.as(t, users[0]).h.G().NotifyRouter.AddListener(listener0)
info := mustCreateConversationForTest(t, ctc, users[0], chat1.TopicType_CHAT,
chat1.ConversationMembersType_TEAM, users[1])
conv, err := utils.GetUnverifiedConv(ctx, tc.Context(), uid, info.Id, types.InboxSourceDataSourceAll)
require.NoError(t, err)
// empty should get one
ch := tc.Context().ParticipantsSource.GetNonblock(ctx, uid, conv.GetConvID(),
types.InboxSourceDataSourceAll)
select {
case pres := <-ch:
require.NoError(t, pres.Err)
require.Equal(t, 2, len(pres.Uids))
case <-time.After(timeout):
require.Fail(t, "no uids")
}
time.Sleep(time.Millisecond * 200)
_, ok := <-ch
require.False(t, ok)
// cached should get one
ch = tc.Context().ParticipantsSource.GetNonblock(ctx, uid, conv.GetConvID(),
types.InboxSourceDataSourceAll)
select {
case pres := <-ch:
require.NoError(t, pres.Err)
require.Equal(t, 2, len(pres.Uids))
case <-time.After(timeout):
require.Fail(t, "no uids")
}
time.Sleep(time.Millisecond * 200)
_, ok = <-ch
require.False(t, ok)
// hash wrong, should get two
err = teams.SetRoleWriter(context.TODO(), tc.G, info.TlfName, users[2].Username)
require.NoError(t, err)
consumeMembersUpdate(t, listener0)
ch = tc.Context().ParticipantsSource.GetNonblock(ctx, uid, conv.GetConvID(),
types.InboxSourceDataSourceAll)
select {
case pres := <-ch:
require.NoError(t, pres.Err)
require.Equal(t, 2, len(pres.Uids))
case <-time.After(timeout):
require.Fail(t, "no uids")
}
select {
case pres := <-ch:
require.NoError(t, pres.Err)
require.Equal(t, 3, len(pres.Uids))
case <-time.After(timeout):
require.Fail(t, "no uids")
}
// cached should get one
ch = tc.Context().ParticipantsSource.GetNonblock(ctx, uid, conv.GetConvID(),
types.InboxSourceDataSourceAll)
select {
case pres := <-ch:
require.NoError(t, pres.Err)
require.Equal(t, 3, len(pres.Uids))
case <-time.After(timeout):
require.Fail(t, "no uids")
}
time.Sleep(time.Millisecond * 200)
_, ok = <-ch
require.False(t, ok)
}