forked from getsentry/sentry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scope_concurrency_test.go
65 lines (55 loc) · 1.3 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
package sentry_test
import (
"fmt"
"net/http/httptest"
"sync"
"testing"
"github.com/getsentry/sentry-go"
)
func TestConcurrentScopeUsage(t *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))
sentry.CaptureException(fmt.Errorf("error %d", x))
scope.ClearBreadcrumbs()
scope.Clone()
}