Debian Codegraph @

health_bench_test.go

raw symbols SCIP
1 package health_test
2
3 import (
4 "math/rand"
5 "net/http"
6 "net/http/httptest"
7 "testing"
8
9 "github.com/TwiN/health"
10 )
11
12 func BenchmarkHealthHandler_ServeHTTP(b *testing.B) {
13 h := health.Handler().WithJSON(true)
14 b.RunParallel(func(pb *testing.PB) {
15 for pb.Next() {
16 request, _ := http.NewRequest("GET", "/health", http.NoBody)
17 responseRecorder := httptest.NewRecorder()
18 h.ServeHTTP(responseRecorder, request)
19 if n := rand.Intn(100); n < 1 {
20 health.SetStatus(health.Down)
21 } else if n < 5 {
22 health.SetStatus(health.Up)
23 }
24 }
25 })
26 b.ReportAllocs()
27 }