-
Notifications
You must be signed in to change notification settings - Fork 214
/
scope_concurrency_test.go
67 lines (57 loc) · 1.46 KB
/
scope_concurrency_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
package sentry_test
import (
"fmt"
"net/http/httptest"
"sync"
"testing"
"github.com/getsentry/sentry-go"
)
func TestConcurrentScopeUsage(_ *testing.T) {
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func(x int) {
defer wg.Done()
sentry.WithScope(func(scope *sentry.Scope) {
touchScope(scope, x)
})
}(i)
wg.Add(1)
go func(x int) {
defer wg.Done()
sentry.ConfigureScope(func(scope *sentry.Scope) {
touchScope(scope, x)
})
}(i)
}
for i := 0; i < 10; i++ {
func(x int) {
sentry.WithScope(func(scope *sentry.Scope) {
touchScope(scope, x)
})
}(i)
func(x int) {
sentry.ConfigureScope(func(scope *sentry.Scope) {
touchScope(scope, x)
})
}(i)
}
// wait for goroutines to finish
wg.Wait()
}
func touchScope(scope *sentry.Scope, x int) {
scope.SetTag("foo", "bar")
scope.SetContext("foo", sentry.Context{"foo": "bar"})
scope.SetExtra("foo", "bar")
scope.SetLevel(sentry.LevelDebug)
scope.SetFingerprint([]string{"foo"})
scope.AddBreadcrumb(&sentry.Breadcrumb{Message: "foo"}, 100)
scope.AddAttachment(&sentry.Attachment{Filename: "foo.txt"})
scope.SetUser(sentry.User{ID: "foo"})
scope.SetRequest(httptest.NewRequest("GET", "/foo", nil))
scope.SetPropagationContext(sentry.NewPropagationContext())
scope.SetSpan(&sentry.Span{TraceID: sentry.TraceIDFromHex("d49d9bf66f13450b81f65bc51cf49c03")})
sentry.CaptureException(fmt.Errorf("error %d", x))
scope.ClearBreadcrumbs()
scope.Clone()
}