-
Notifications
You must be signed in to change notification settings - Fork 2
/
pubsub_test.go
93 lines (82 loc) · 2.11 KB
/
pubsub_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
package firestore_test
import (
"os"
"strconv"
"testing"
"time"
"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill-firestore/pkg/firestore"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/ThreeDotsLabs/watermill/pubsub/tests"
)
func createPubSub(t *testing.T) (message.Publisher, message.Subscriber) {
return createPubSubWithSubscriptionName(t, "topic")
}
func createPubSubWithSubscriptionName(t *testing.T, subscriptionName string) (message.Publisher, message.Subscriber) {
logger := watermill.NewStdLogger(true, true)
pub, err := firestore.NewPublisher(
firestore.PublisherConfig{
ProjectID: os.Getenv("FIRESTORE_PROJECT_ID"),
PubSubRootCollection: "test-root",
MessagePublishTimeout: time.Second * 60,
},
logger,
)
if err != nil {
t.Fatal(err)
}
sub, err := firestore.NewSubscriber(
firestore.SubscriberConfig{
ProjectID: os.Getenv("FIRESTORE_PROJECT_ID"),
PubSubRootCollection: "test-root",
GenerateSubscriptionName: func(topic string) string { return topic + "_" + subscriptionName },
Timeout: time.Second * 30,
},
logger,
)
if err != nil {
panic(err)
}
return pub, sub
}
func TestPublishSubscribe(t *testing.T) {
tests.TestPubSub(
t,
tests.Features{
ConsumerGroups: true,
ExactlyOnceDelivery: false,
GuaranteedOrder: false,
Persistent: true,
},
createPubSub,
createPubSubWithSubscriptionName,
)
}
func createPubSubBench(n int) (message.Publisher, message.Subscriber) {
logger := watermill.NewStdLogger(true, false)
pub, err := firestore.NewPublisher(
firestore.PublisherConfig{
ProjectID: os.Getenv("FIRESTORE_PROJECT_ID"),
},
logger,
)
if err != nil {
panic(err)
}
sub, err := firestore.NewSubscriber(
firestore.SubscriberConfig{
GenerateSubscriptionName: func(topic string) string {
return topic + strconv.Itoa(n)
},
ProjectID: os.Getenv("FIRESTORE_PROJECT_ID"),
},
logger,
)
if err != nil {
panic(err)
}
return pub, sub
}
func BenchmarkPublishSubscribe(b *testing.B) {
tests.BenchSubscriber(b, createPubSubBench)
}