-
Notifications
You must be signed in to change notification settings - Fork 1
/
store.go
62 lines (56 loc) · 1.53 KB
/
store.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
package testing
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
v1 "github.com/xmtp/proto/v3/go/message_api/v1"
"github.com/xmtp/xmtpd/pkg/api"
"github.com/xmtp/xmtpd/pkg/context"
crdttest "github.com/xmtp/xmtpd/pkg/crdt/testing"
"github.com/xmtp/xmtpd/pkg/node"
test "github.com/xmtp/xmtpd/pkg/testing"
)
func TestTopicBootstrap(t testing.TB, storeMaker func(t testing.TB, ctx context.Context) node.NodeStore) {
topics := []string{"topic1", "topic2", "topic3"}
ctx := test.NewContext(t)
store := storeMaker(t, ctx)
node := NewNode(t,
WithContext(ctx),
WithStore(store),
)
for i, topic := range topics {
node.PublishRandom(t, topic, i+1)
}
res, err := store.Topics()
require.NoError(t, err)
require.ElementsMatch(t, res, topics)
node.Close()
ctx = test.NewContext(t)
store = storeMaker(t, ctx)
node = NewNode(t,
WithContext(ctx),
WithStore(store),
)
for i, topic := range topics {
envs := node.RequireQuery(t, topic)
require.Len(t, envs, i+1)
}
node.Close()
}
func BenchmarkQuery(b *testing.B, ctx context.Context, topic *crdttest.TestStore, start, end uint64, pageSize uint32) {
b.Run(fmt.Sprintf("%d/%d/%d", start, end, pageSize), func(b *testing.B) {
for n := 0; n < b.N; n++ {
var resp *v1.QueryResponse
var err error
for count := end - start + 1; count > 0; count -= uint64(len(resp.Envelopes)) {
resp, err = topic.Query(ctx,
api.NewQuery("",
api.TimeRange(start, end),
api.Limit(pageSize),
api.Cursor(resp),
))
require.NoError(b, err)
}
}
})
}