forked from PostHog/posthog-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
66 lines (53 loc) · 1.55 KB
/
message_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
package posthog
import (
"reflect"
"testing"
)
func TestMessageQueuePushMaxBatchSize(t *testing.T) {
m0, _ := makeMessage(Capture{
DistinctId: "1",
Event: "A",
}, maxMessageBytes)
m1, _ := makeMessage(Capture{
DistinctId: "2",
Event: "A",
}, maxMessageBytes)
q := messageQueue{
maxBatchSize: 2,
maxBatchBytes: maxBatchBytes,
}
if msgs := q.push(m0); msgs != nil {
t.Error("unexpected message batch returned after pushing only one message")
}
if msgs := q.push(m1); !reflect.DeepEqual(msgs, []message{m0, m1}) {
t.Error("invalid message batch returned after pushing two messages:", msgs)
}
}
func TestMessageQueuePushMaxBatchBytes(t *testing.T) {
m0, _ := makeMessage(Capture{
DistinctId: "1",
Event: "A",
}, maxMessageBytes)
m1, _ := makeMessage(Capture{
DistinctId: "2",
Event: "A",
}, maxMessageBytes)
q := messageQueue{
maxBatchSize: 100,
maxBatchBytes: len(m0.json) + 1,
}
if msgs := q.push(m0); msgs != nil {
t.Error("unexpected message batch returned after pushing only one message")
}
if msgs := q.push(m1); !reflect.DeepEqual(msgs, []message{m0}) {
t.Error("invalid message batch returned after pushing two messages:", msgs)
}
if !reflect.DeepEqual(q.pending, []message{m1}) {
t.Error("invalid state of the message queue after pushing two messages:", q.pending)
}
}
func TestMakeMessageTooBig(t *testing.T) {
if _, err := makeMessage(Capture{DistinctId: "1"}, 1); err != ErrMessageTooBig {
t.Error("invalid error returned when creating a message bigger than the limit:", err)
}
}