2022-03-05 19:10:19 +03:00
|
|
|
package opentracing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
opentracing "github.com/opentracing/opentracing-go"
|
2023-05-07 19:38:45 +03:00
|
|
|
"go.unistack.org/micro/v4/metadata"
|
2022-03-05 19:10:19 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStartSpanFromIncomingContext(t *testing.T) {
|
|
|
|
md := metadata.New(2)
|
|
|
|
md.Set("key", "val")
|
|
|
|
|
|
|
|
var g sync.WaitGroup
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
ctx = metadata.NewIncomingContext(ctx, md)
|
|
|
|
|
|
|
|
tracer := opentracing.GlobalTracer()
|
|
|
|
|
|
|
|
g.Add(8000)
|
|
|
|
cherr := make(chan error)
|
|
|
|
for i := 0; i < 8000; i++ {
|
|
|
|
go func() {
|
|
|
|
defer g.Done()
|
2023-09-01 08:08:34 +03:00
|
|
|
_, sp, err := startSpanFromIncomingContext(ctx, tracer, "test")
|
|
|
|
if err != nil {
|
|
|
|
cherr <- err
|
|
|
|
}
|
2022-03-05 19:10:19 +03:00
|
|
|
sp.Finish()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
default:
|
|
|
|
g.Wait()
|
|
|
|
close(cherr)
|
|
|
|
case err, ok := <-cherr:
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|