You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
Minor refactoring (#4417)
This commit is contained in:
@@ -64,16 +64,17 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
done := make(chan struct{})
|
||||
first := make(chan struct{}, goroutines)
|
||||
var wg sync.WaitGroup
|
||||
var wg, someWork sync.WaitGroup
|
||||
for i := 0; i < goroutines; i++ {
|
||||
wg.Add(1)
|
||||
someWork.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
assert.NoError(t, exp.Export(ctx, rm))
|
||||
assert.NoError(t, exp.ForceFlush(ctx))
|
||||
|
||||
// Ensure some work is done before shutting down.
|
||||
first <- struct{}{}
|
||||
someWork.Done()
|
||||
|
||||
for {
|
||||
_ = exp.Export(ctx, rm)
|
||||
@@ -88,10 +89,7 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
|
||||
}()
|
||||
}
|
||||
|
||||
for i := 0; i < goroutines; i++ {
|
||||
<-first
|
||||
}
|
||||
close(first)
|
||||
someWork.Wait()
|
||||
assert.NoError(t, exp.Shutdown(ctx))
|
||||
assert.ErrorIs(t, exp.Shutdown(ctx), errShutdown)
|
||||
|
||||
|
||||
@@ -47,16 +47,17 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
|
||||
rm := new(metricdata.ResourceMetrics)
|
||||
|
||||
done := make(chan struct{})
|
||||
first := make(chan struct{}, goroutines)
|
||||
var wg sync.WaitGroup
|
||||
var wg, someWork sync.WaitGroup
|
||||
for i := 0; i < goroutines; i++ {
|
||||
wg.Add(1)
|
||||
someWork.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
assert.NoError(t, exp.Export(ctx, rm))
|
||||
assert.NoError(t, exp.ForceFlush(ctx))
|
||||
|
||||
// Ensure some work is done before shutting down.
|
||||
first <- struct{}{}
|
||||
someWork.Done()
|
||||
|
||||
for {
|
||||
_ = exp.Export(ctx, rm)
|
||||
@@ -71,10 +72,7 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
|
||||
}()
|
||||
}
|
||||
|
||||
for i := 0; i < goroutines; i++ {
|
||||
<-first
|
||||
}
|
||||
close(first)
|
||||
someWork.Wait()
|
||||
assert.NoError(t, exp.Shutdown(ctx))
|
||||
assert.ErrorIs(t, exp.Shutdown(ctx), errShutdown)
|
||||
|
||||
|
||||
@@ -47,16 +47,17 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
|
||||
rm := new(metricdata.ResourceMetrics)
|
||||
|
||||
done := make(chan struct{})
|
||||
first := make(chan struct{}, goroutines)
|
||||
var wg sync.WaitGroup
|
||||
var wg, someWork sync.WaitGroup
|
||||
for i := 0; i < goroutines; i++ {
|
||||
wg.Add(1)
|
||||
someWork.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
assert.NoError(t, exp.Export(ctx, rm))
|
||||
assert.NoError(t, exp.ForceFlush(ctx))
|
||||
|
||||
// Ensure some work is done before shutting down.
|
||||
first <- struct{}{}
|
||||
someWork.Done()
|
||||
|
||||
for {
|
||||
_ = exp.Export(ctx, rm)
|
||||
@@ -71,10 +72,7 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
|
||||
}()
|
||||
}
|
||||
|
||||
for i := 0; i < goroutines; i++ {
|
||||
<-first
|
||||
}
|
||||
close(first)
|
||||
someWork.Wait()
|
||||
assert.NoError(t, exp.Shutdown(ctx))
|
||||
assert.ErrorIs(t, exp.Shutdown(ctx), errShutdown)
|
||||
|
||||
|
||||
@@ -345,7 +345,7 @@ func TestPeriodicReaderFlushesPending(t *testing.T) {
|
||||
return nil
|
||||
}})
|
||||
r.RegisterProducer(testExternalProducer{})
|
||||
assert.Equal(t, context.DeadlineExceeded, r.ForceFlush(context.Background()), "timeout error not returned")
|
||||
assert.ErrorIs(t, r.ForceFlush(context.Background()), context.DeadlineExceeded)
|
||||
assert.False(t, *called, "exporter Export method called when it should have failed before export")
|
||||
|
||||
// Ensure Reader is allowed clean up attempt.
|
||||
@@ -368,7 +368,7 @@ func TestPeriodicReaderFlushesPending(t *testing.T) {
|
||||
return []metricdata.ScopeMetrics{testScopeMetricsA}, nil
|
||||
},
|
||||
})
|
||||
assert.Equal(t, context.DeadlineExceeded, r.ForceFlush(context.Background()), "timeout error not returned")
|
||||
assert.ErrorIs(t, r.ForceFlush(context.Background()), context.DeadlineExceeded)
|
||||
assert.False(t, *called, "exporter Export method called when it should have failed before export")
|
||||
|
||||
// Ensure Reader is allowed clean up attempt.
|
||||
@@ -400,7 +400,7 @@ func TestPeriodicReaderFlushesPending(t *testing.T) {
|
||||
return nil
|
||||
}})
|
||||
r.RegisterProducer(testExternalProducer{})
|
||||
assert.Equal(t, context.DeadlineExceeded, r.Shutdown(context.Background()), "timeout error not returned")
|
||||
assert.ErrorIs(t, r.Shutdown(context.Background()), context.DeadlineExceeded)
|
||||
assert.False(t, *called, "exporter Export method called when it should have failed before export")
|
||||
})
|
||||
|
||||
@@ -420,7 +420,7 @@ func TestPeriodicReaderFlushesPending(t *testing.T) {
|
||||
return []metricdata.ScopeMetrics{testScopeMetricsA}, nil
|
||||
},
|
||||
})
|
||||
assert.Equal(t, context.DeadlineExceeded, r.Shutdown(context.Background()), "timeout error not returned")
|
||||
assert.ErrorIs(t, r.Shutdown(context.Background()), context.DeadlineExceeded)
|
||||
assert.False(t, *called, "exporter Export method called when it should have failed before export")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user