mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-18 03:22:12 +02:00
sdk/metric: Fix goroutine leaks in tests (#4352)
This commit is contained in:
parent
088ac8e179
commit
d8d3502efc
@ -44,7 +44,6 @@ func TestCacheConcurrentSafe(t *testing.T) {
|
||||
const (
|
||||
key = "k"
|
||||
goroutines = 10
|
||||
timeoutSec = 5
|
||||
)
|
||||
|
||||
c := cache[string, int]{}
|
||||
@ -65,12 +64,9 @@ func TestCacheConcurrentSafe(t *testing.T) {
|
||||
close(done)
|
||||
}()
|
||||
|
||||
assert.Eventually(t, func() bool {
|
||||
select {
|
||||
case <-done:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}, timeoutSec*time.Second, 10*time.Millisecond)
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
assert.Fail(t, "timeout")
|
||||
}
|
||||
}
|
||||
|
@ -35,42 +35,54 @@ func TestMeterConcurrentSafe(t *testing.T) {
|
||||
const name = "TestMeterConcurrentSafe meter"
|
||||
mp := NewMeterProvider()
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
_ = mp.Meter(name)
|
||||
}()
|
||||
|
||||
_ = mp.Meter(name)
|
||||
<-done
|
||||
}
|
||||
|
||||
func TestForceFlushConcurrentSafe(t *testing.T) {
|
||||
mp := NewMeterProvider()
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
_ = mp.ForceFlush(context.Background())
|
||||
}()
|
||||
|
||||
_ = mp.ForceFlush(context.Background())
|
||||
<-done
|
||||
}
|
||||
|
||||
func TestShutdownConcurrentSafe(t *testing.T) {
|
||||
mp := NewMeterProvider()
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
_ = mp.Shutdown(context.Background())
|
||||
}()
|
||||
|
||||
_ = mp.Shutdown(context.Background())
|
||||
<-done
|
||||
}
|
||||
|
||||
func TestMeterAndShutdownConcurrentSafe(t *testing.T) {
|
||||
const name = "TestMeterAndShutdownConcurrentSafe meter"
|
||||
mp := NewMeterProvider()
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
_ = mp.Shutdown(context.Background())
|
||||
}()
|
||||
|
||||
_ = mp.Meter(name)
|
||||
<-done
|
||||
}
|
||||
|
||||
func TestMeterDoesNotPanicForEmptyMeterProvider(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user