-
Notifications
You must be signed in to change notification settings - Fork 214
/
span_recorder_test.go
63 lines (57 loc) · 1.52 KB
/
span_recorder_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
package sentry
import (
"bytes"
"context"
"fmt"
"io"
"testing"
)
func Test_spanRecorder_record(t *testing.T) {
testRootSpan := StartSpan(context.Background(), "test", WithTransactionName("test transaction"))
for _, tt := range []struct {
name string
maxSpans int
toRecordSpans int
expectOverflow bool
}{
{
name: "record span without problems",
maxSpans: defaultMaxSpans,
toRecordSpans: 1,
expectOverflow: false,
},
{
name: "record span with overflow",
maxSpans: 2,
toRecordSpans: 4,
expectOverflow: true,
},
} {
t.Run(tt.name, func(t *testing.T) {
logBuffer := bytes.Buffer{}
Logger.SetOutput(&logBuffer)
defer Logger.SetOutput(io.Discard)
spanRecorder := spanRecorder{}
currentHub.BindClient(&Client{
options: ClientOptions{
MaxSpans: tt.maxSpans,
},
})
// Unbind the client afterwards, to not affect other tests
defer currentHub.stackTop().SetClient(nil)
for i := 0; i < tt.toRecordSpans; i++ {
child := testRootSpan.StartChild(fmt.Sprintf("test %d", i))
spanRecorder.record(child)
}
if tt.expectOverflow {
assertNotEqual(t, len(spanRecorder.spans), tt.toRecordSpans, "expected overflow")
} else {
assertEqual(t, len(spanRecorder.spans), tt.toRecordSpans, "expected no overflow")
}
// check if Logger was called for overflow messages
if bytes.Contains(logBuffer.Bytes(), []byte("Too many spans")) && !tt.expectOverflow {
t.Error("unexpected overflow log")
}
})
}
}