feat: slow threshold customizable in rest (#1189)

* feat: slow threshold customizable in rest

* feat: slow threshold customizable in rest
This commit is contained in:
Kevin Wan
2021-11-01 14:48:26 +08:00
committed by GitHub
parent 785d100be9
commit ebc90720ea
2 changed files with 19 additions and 5 deletions

View File

@@ -53,7 +53,7 @@ func TestLogHandlerSlow(t *testing.T) {
for _, logHandler := range handlers {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
handler := logHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(slowThreshold + time.Millisecond*50)
time.Sleep(defaultSlowThreshold + time.Millisecond*50)
}))
resp := httptest.NewRecorder()
@@ -100,6 +100,12 @@ func TestDetailedLogHandler_Hijack(t *testing.T) {
})
}
func TestSetSlowThreshold(t *testing.T) {
assert.Equal(t, defaultSlowThreshold, slowThreshold.Load())
SetSlowThreshold(time.Second)
assert.Equal(t, time.Second, slowThreshold.Load())
}
func BenchmarkLogHandler(b *testing.B) {
b.ReportAllocs()