-
Notifications
You must be signed in to change notification settings - Fork 251
Expand file tree
/
Copy pathspan_recorder_test.go
More file actions
65 lines (58 loc) · 1.58 KB
/
span_recorder_test.go
File metadata and controls
65 lines (58 loc) · 1.58 KB
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
package sentry
import (
"bytes"
"context"
"fmt"
"io"
"testing"
"github.com/getsentry/sentry-go/internal/debuglog"
)
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{}
debuglog.SetOutput(&logBuffer)
defer debuglog.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 debuglog was called for overflow messages
if bytes.Contains(logBuffer.Bytes(), []byte("Too many spans")) && !tt.expectOverflow {
t.Error("unexpected overflow log")
}
})
}
}