Skip to content

Commit

Permalink
tests: add monitoring middleware concurrent test (#14443) (#14444)
Browse files Browse the repository at this point in the history
(cherry picked from commit b54be36)

Co-authored-by: Kostiantyn Masliuk <[email protected]>
  • Loading branch information
mergify[bot] and 1pkg authored Oct 25, 2024
1 parent f58eda4 commit 648a654
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions internal/beater/middleware/monitoring_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package middleware

import (
"sync"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -157,4 +158,33 @@ func TestMonitoringHandler(t *testing.T) {
mockMonitoringNil,
)
})

t.Run("Parallel", func(t *testing.T) {
const i = 3
reader := sdkmetric.NewManualReader(sdkmetric.WithTemporalitySelector(
func(ik sdkmetric.InstrumentKind) metricdata.Temporality {
return metricdata.DeltaTemporality
},
))
mp := sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader))
m := MonitoringMiddleware(mockMonitoringNil, mp)
c, _ := DefaultContextWithResponseRecorder()
var wg sync.WaitGroup
for range i {
wg.Add(1)
go func() {
Apply(m, HandlerIdle)(c)
wg.Done()
}()
}
wg.Wait()
monitoringtest.ExpectOtelMetrics(t, reader, map[string]interface{}{
"http.server." + string(request.IDRequestCount): i,
"http.server." + string(request.IDResponseCount): i,
"http.server." + string(request.IDResponseValidCount): i,
"http.server." + string(request.IDUnset): i,

"http.server.request.duration": i,
})
})
}

0 comments on commit 648a654

Please sign in to comment.