fix: OpenTelemetry unit tests

This commit is contained in:
mmatur 2024-01-23 09:48:46 +01:00
parent 9843757834
commit a3ac456199
No known key found for this signature in database
GPG key ID: 2FFE42FC256CFF8E

View file

@ -287,8 +287,8 @@ func TestOpenTelemetry_GaugeCollectorSet(t *testing.T) {
}
func TestOpenTelemetry(t *testing.T) {
c := make(chan *string)
defer close(c)
c := make(chan *string, 5)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gzr, err := gzip.NewReader(r.Body)
require.NoError(t, err)
@ -308,7 +308,11 @@ func TestOpenTelemetry(t *testing.T) {
w.WriteHeader(http.StatusOK)
}))
defer ts.Close()
t.Cleanup(func() {
close(c)
ts.Close()
})
sURL, err := url.Parse(ts.URL)
require.NoError(t, err)
@ -439,10 +443,11 @@ func TestOpenTelemetry(t *testing.T) {
assertMessage(t, *msgEntryPointReqDurationHistogram, expectedEntryPointReqDuration)
// We need to unlock the HTTP Server for the last export call when stopping
// OpenTelemetry.
// Stopping OpenTelemetry.
go func() {
<-c
StopOpenTelemetry()
}()
StopOpenTelemetry()
// We need to unlock the HTTP Server for the last export call.
<-c
}