File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,8 +84,19 @@ func (e *Expectation) ToBeFalse() {
8484}
8585
8686func (e * Expectation ) NotToPanic () {
87- if actual := recover (); actual != nil {
88- e .fail (fmt .Sprintf ("Expected panic\n \t %v\n to have not been raised" , actual ))
87+ switch a := e .actual .(type ) {
88+ case func ():
89+ func () {
90+ defer func () {
91+ if recovered := recover (); recovered != nil {
92+ e .fail (fmt .Sprintf ("Expected panic\n \t %v\n to have not been raised" , recovered ))
93+ }
94+ }()
95+
96+ a ()
97+ }()
98+ default :
99+ e .fail (fmt .Sprintf ("Cannot check if non-func value\n \t %v\n is truthy" , a ))
89100 }
90101}
91102
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ package tools
1818
1919import (
2020 _ "github.com/client9/misspell/cmd/misspell"
21+ _ "github.com/gogo/protobuf/protoc-gen-gogofast"
2122 _ "github.com/golangci/golangci-lint/cmd/golangci-lint"
2223 _ "github.com/itchyny/gojq"
2324 _ "golang.org/x/tools/cmd/stringer"
24- _ "github.com/gogo/protobuf/protoc-gen-gogofast"
2525)
Original file line number Diff line number Diff line change @@ -217,6 +217,44 @@ func (h *Harness) TestTracer(subjectFactory func() trace.Tracer) {
217217 e .Expect (csc .TraceID ()).NotToEqual (psc .TraceID ())
218218 e .Expect (csc .SpanID ()).NotToEqual (psc .SpanID ())
219219 })
220+
221+ t .Run ("all methods are safe to be called concurrently" , func (t * testing.T ) {
222+ t .Parallel ()
223+
224+ e := matchers .NewExpecter (t )
225+ tracer := subjectFactory ()
226+
227+ ctx , parent := tracer .Start (context .Background (), "span" )
228+
229+ runner := func (tp trace.Tracer ) <- chan struct {} {
230+ done := make (chan struct {})
231+ go func (tp trace.Tracer ) {
232+ var wg sync.WaitGroup
233+ for i := 0 ; i < 20 ; i ++ {
234+ wg .Add (1 )
235+ go func (name string ) {
236+ defer wg .Done ()
237+ _ , child := tp .Start (ctx , name )
238+
239+ psc := parent .SpanContext ()
240+ csc := child .SpanContext ()
241+
242+ e .Expect (csc .TraceID ()).ToEqual (psc .TraceID ())
243+ e .Expect (csc .SpanID ()).NotToEqual (psc .SpanID ())
244+ }(fmt .Sprintf ("span %d" , i ))
245+ }
246+ wg .Wait ()
247+ done <- struct {}{}
248+ }(tp )
249+ return done
250+ }
251+
252+ e .Expect (func () {
253+ done := runner (tracer )
254+
255+ <- done
256+ }).NotToPanic ()
257+ })
220258 })
221259
222260 h .testSpan (subjectFactory )
You can’t perform that action at this time.
0 commit comments