@@ -3,12 +3,39 @@ package traceparser
3
3
import (
4
4
"bytes"
5
5
"fmt"
6
+ "runtime"
6
7
"strings"
7
8
"testing"
8
9
9
10
"github.com/stretchr/testify/require"
10
11
)
11
12
13
+ func TestGenerateTrace (t * testing.T ) {
14
+ stacks := make (chan string )
15
+ go func () {
16
+ var stacksBuffer = make ([]byte , 1000 )
17
+ for {
18
+ // Capture stacks for all existing goroutines.
19
+ // Note: runtime.GoroutineProfile() would be better but we can't use it at the moment because
20
+ // it doesn't give us `gid` for each routine, see https://github.com/golang/go/issues/59663
21
+ n := runtime .Stack (stacksBuffer , true )
22
+
23
+ // If we couldn't read everything, increase the buffer and try again.
24
+ if n >= len (stacksBuffer ) {
25
+ stacksBuffer = make ([]byte , n * 2 )
26
+ } else {
27
+ stacks <- string (stacksBuffer [0 :n ])
28
+ break
29
+ }
30
+ }
31
+ }()
32
+
33
+ t .Log (<- stacks )
34
+
35
+ // Note: uncomment to show the output so you can update it manually in tests below.
36
+ // t.Fail()
37
+ }
38
+
12
39
func TestParseEmpty (t * testing.T ) {
13
40
var require = require .New (t )
14
41
@@ -17,11 +44,11 @@ func TestParseEmpty(t *testing.T) {
17
44
}
18
45
19
46
var tracetext = []byte (`
20
- goroutine 18 [running]:
21
- testing.(*M).startAlarm .func1()
22
- C:/Users/name/scoop/apps/ go/current/src/testing/testing .go:2241 +0x3c5
23
- created by time.goFunc
24
- C:/Users/name/scoop/apps/ go/current/src/time/sleep .go:176 +0x32
47
+ goroutine 7 [running]:
48
+ github.com/getsentry/sentry-go/internal/traceparser.TestGenerateTrace .func1()
49
+ c:/dev/sentry- go/internal/traceparser/parser_test .go:23 +0x6c
50
+ created by github.com/getsentry/sentry-go/internal/traceparser.TestGenerateTrace in goroutine 6
51
+ c:/dev/sentry- go/internal/traceparser/parser_test .go:17 +0x7f
25
52
26
53
goroutine 1 [chan receive]:
27
54
testing.(*T).Run(0xc00006f6c0, {0x672288?, 0x180fd3?}, 0x6b5f98)
@@ -78,10 +105,10 @@ func TestParse(t *testing.T) {
78
105
i ++
79
106
}
80
107
81
- checkTrace (18 , `testing.(*M).startAlarm .func1()
82
- C:/Users/name/scoop/apps/ go/current/src/testing/testing .go:2241 +0x3c5
83
- created by time.goFunc
84
- C:/Users/name/scoop/apps/ go/current/src/time/sleep .go:176 +0x32 ` )
108
+ checkTrace (7 , `github.com/getsentry/sentry-go/internal/traceparser.TestGenerateTrace .func1()
109
+ c:/dev/sentry- go/internal/traceparser/parser_test .go:23 +0x6c
110
+ created by github.com/getsentry/sentry-go/internal/traceparser.TestGenerateTrace in goroutine 6
111
+ c:/dev/sentry- go/internal/traceparser/parser_test .go:17 +0x7f ` )
85
112
86
113
checkTrace (1 , `testing.(*T).Run(0xc00006f6c0, {0x672288?, 0x180fd3?}, 0x6b5f98)
87
114
C:/Users/name/scoop/apps/go/current/src/testing/testing.go:1630 +0x405
@@ -144,13 +171,13 @@ func TestFrames(t *testing.T) {
144
171
}
145
172
146
173
var expected = strings .Split (strings .TrimLeft (`
147
- Trace 0: goroutine 18 with at most 2 frames
148
- Func = testing.(*M).startAlarm .func1
149
- File = C:/Users/name/scoop/apps/ go/current/src/testing/testing .go
150
- Line = 2241
151
- Func = time.goFunc
152
- File = C:/Users/name/scoop/apps/ go/current/src/time/sleep .go
153
- Line = 176
174
+ Trace 0: goroutine 7 with at most 2 frames
175
+ Func = github.com/getsentry/sentry-go/internal/traceparser.TestGenerateTrace .func1
176
+ File = c:/dev/sentry- go/internal/traceparser/parser_test .go
177
+ Line = 23
178
+ Func = github.com/getsentry/sentry-go/internal/traceparser.TestGenerateTrace
179
+ File = c:/dev/sentry- go/internal/traceparser/parser_test .go
180
+ Line = 17
154
181
Trace 1: goroutine 1 with at most 6 frames
155
182
Func = testing.(*T).Run
156
183
File = C:/Users/name/scoop/apps/go/current/src/testing/testing.go
@@ -228,13 +255,13 @@ func TestFramesReversed(t *testing.T) {
228
255
}
229
256
230
257
var expected = strings .Split (strings .TrimLeft (`
231
- Trace 0: goroutine 18 with at most 2 frames
232
- Func = time.goFunc
233
- File = C:/Users/name/scoop/apps/ go/current/src/time/sleep .go
234
- Line = 176
235
- Func = testing.(*M).startAlarm .func1
236
- File = C:/Users/name/scoop/apps/ go/current/src/testing/testing .go
237
- Line = 2241
258
+ Trace 0: goroutine 7 with at most 2 frames
259
+ Func = github.com/getsentry/sentry-go/internal/traceparser.TestGenerateTrace
260
+ File = c:/dev/sentry- go/internal/traceparser/parser_test .go
261
+ Line = 17
262
+ Func = github.com/getsentry/sentry-go/internal/traceparser.TestGenerateTrace .func1
263
+ File = c:/dev/sentry- go/internal/traceparser/parser_test .go
264
+ Line = 23
238
265
Trace 1: goroutine 1 with at most 6 frames
239
266
Func = main.main
240
267
File = _testmain.go
0 commit comments