Skip to content

Commit

Permalink
test: Added manual test for concurrent setters
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Jul 26, 2019
1 parent 50a4841 commit b1d347b
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ script:
- golangci-lint run
- go build
- go test
- go test -race

notifications:
webhooks:
Expand Down
97 changes: 97 additions & 0 deletions tests/locks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package main

import (
"errors"
"fmt"
"time"

"github.com/getsentry/sentry-go"
)

func main() {
i := 0

if err := sentry.Init(sentry.ClientOptions{
Dsn: "",
BeforeSend: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {
i++
if i%1000 == 0 {
fmt.Println(i)
}
return nil
},
}); err != nil {
fmt.Println(err)
}

for i := 0; i < 10000; i++ {
go func(x int) {
sentry.WithScope(func(scope *sentry.Scope) {
scope.SetTag("foo", "bar")
scope.SetContext("foo", "bar")
scope.SetExtra("foo", "bar")
scope.SetLevel(sentry.LevelDebug)
scope.SetTransaction("foo")
scope.SetFingerprint([]string{"foo"})
scope.AddBreadcrumb(&sentry.Breadcrumb{Timestamp: 1337, Message: "foo"}, 100)
scope.SetUser(sentry.User{ID: "foo"})
scope.SetRequest(sentry.Request{URL: "foo"})

sentry.CaptureException(errors.New(string(x)))
})
}(i)

go func(x int) {
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetTag("foo", "bar")
scope.SetContext("foo", "bar")
scope.SetExtra("foo", "bar")
scope.SetLevel(sentry.LevelDebug)
scope.SetTransaction("foo")
scope.SetFingerprint([]string{"foo"})
scope.AddBreadcrumb(&sentry.Breadcrumb{Timestamp: 1337, Message: "foo"}, 100)
scope.SetUser(sentry.User{ID: "foo"})
scope.SetRequest(sentry.Request{URL: "foo"})

sentry.CaptureException(errors.New(string(x)))
})
}(i)
}

for i := 0; i < 10000; i++ {
func(x int) {
sentry.WithScope(func(scope *sentry.Scope) {
scope.SetTag("foo", "bar")
scope.SetContext("foo", "bar")
scope.SetExtra("foo", "bar")
scope.SetLevel(sentry.LevelDebug)
scope.SetTransaction("foo")
scope.SetFingerprint([]string{"foo"})
scope.AddBreadcrumb(&sentry.Breadcrumb{Timestamp: 1337, Message: "foo"}, 100)
scope.SetUser(sentry.User{ID: "foo"})
scope.SetRequest(sentry.Request{URL: "foo"})

sentry.CaptureException(errors.New(string(x)))
})
}(i)

func(x int) {
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetTag("foo", "bar")
scope.SetContext("foo", "bar")
scope.SetExtra("foo", "bar")
scope.SetLevel(sentry.LevelDebug)
scope.SetTransaction("foo")
scope.SetFingerprint([]string{"foo"})
scope.AddBreadcrumb(&sentry.Breadcrumb{Timestamp: 1337, Message: "foo"}, 100)
scope.SetUser(sentry.User{ID: "foo"})
scope.SetRequest(sentry.Request{URL: "foo"})

sentry.CaptureException(errors.New(string(x)))
})
}(i)
}

// wait for goroutines to finish
time.Sleep(time.Second)
}

0 comments on commit b1d347b

Please sign in to comment.