Revert "fix: api group set timeout: 0s not working." (#4931)

This commit is contained in:
Kevin Wan
2025-06-08 23:14:38 +08:00
committed by GitHub
parent 19fec36d24
commit 0f2b589d4d
5 changed files with 17 additions and 29 deletions

View File

@@ -64,9 +64,6 @@ Verbose: true
`,
}
minuteDuration := time.Minute
secondDuration := time.Second
routes := []featuredRoutes{
{
jwt: jwtSetting{},
@@ -76,7 +73,7 @@ Verbose: true
Path: "/",
Handler: func(w http.ResponseWriter, r *http.Request) {},
}},
timeout: &minuteDuration,
timeout: time.Minute,
},
{
priority: true,
@@ -87,7 +84,7 @@ Verbose: true
Path: "/",
Handler: func(w http.ResponseWriter, r *http.Request) {},
}},
timeout: &secondDuration,
timeout: time.Second,
},
{
priority: true,
@@ -230,8 +227,8 @@ Verbose: true
}))
timeout := time.Second * 3
if route.timeout != nil {
timeout = *route.timeout
if route.timeout > timeout {
timeout = route.timeout
}
assert.Equal(t, timeout, ng.timeout)
})
@@ -239,14 +236,10 @@ Verbose: true
}
}
func getPtrTimeDuration(dur time.Duration) *time.Duration {
return &dur
}
func TestEngine_checkedTimeout(t *testing.T) {
tests := []struct {
name string
timeout *time.Duration
timeout time.Duration
expect time.Duration
}{
{
@@ -255,24 +248,19 @@ func TestEngine_checkedTimeout(t *testing.T) {
},
{
name: "less",
timeout: getPtrTimeDuration(time.Millisecond * 500),
timeout: time.Millisecond * 500,
expect: time.Millisecond * 500,
},
{
name: "equal",
timeout: getPtrTimeDuration(time.Second),
timeout: time.Second,
expect: time.Second,
},
{
name: "more",
timeout: getPtrTimeDuration(time.Millisecond * 1500),
timeout: time.Millisecond * 1500,
expect: time.Millisecond * 1500,
},
{
name: "set zero",
timeout: getPtrTimeDuration(0),
expect: 0,
},
}
ng := newEngine(RestConf{