1
0
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:
Robert Pająk 2023-07-25 10:54:08 +02:00 committed by GitHub
parent 088ac8e179
commit d8d3502efc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 9 deletions

View File

@ -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")
}
}

View File

@ -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) {