feat: support customizing timeout for specific route (#1203)

* feat: support customizing timeout for specific route

* test: add more tests
This commit is contained in:
Kevin Wan
2021-11-03 22:20:32 +08:00
committed by GitHub
parent 01786c5e63
commit 3ede597a15
5 changed files with 65 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/tal-tech/go-zero/core/conf"
@@ -154,6 +155,41 @@ Verbose: true
}
}
func TestEngine_checkedTimeout(t *testing.T) {
tests := []struct {
name string
timeout time.Duration
expect time.Duration
}{
{
name: "not set",
expect: time.Second,
},
{
name: "less",
timeout: time.Millisecond * 500,
expect: time.Millisecond * 500,
},
{
name: "equal",
timeout: time.Second,
expect: time.Second,
},
{
name: "more",
timeout: time.Millisecond * 1500,
expect: time.Millisecond * 1500,
},
}
ng := newEngine(RestConf{
Timeout: 1000,
})
for _, test := range tests {
assert.Equal(t, test.expect, ng.checkedTimeout(test.timeout))
}
}
type mockedRouter struct{}
func (m mockedRouter) ServeHTTP(writer http.ResponseWriter, request *http.Request) {