use default value when the specified timeout is 0s

This commit is contained in:
Abu Kashem 2020-11-18 12:01:27 -05:00
parent 6dddea5abf
commit 0090e27bd3
No known key found for this signature in database
GPG Key ID: 76146D1A14E658ED
2 changed files with 13 additions and 1 deletions

View File

@ -69,7 +69,10 @@ func WithRequestDeadline(handler http.Handler, longRunning request.LongRunningRe
return
}
timeout = userSpecifiedTimeout
// if the user has specified a timeout of 0s, this means no timeout, so we should use the maximum timeout allowed.
if userSpecifiedTimeout != 0 {
timeout = userSpecifiedTimeout
}
}
ctx, cancel := context.WithTimeout(ctx, timeout)

View File

@ -94,6 +94,15 @@ func TestWithRequestDeadline(t *testing.T) {
deadlineExpected: 14 * time.Second, // to account for the delay in verification
statusCodeExpected: http.StatusOK,
},
{
name: "the specified timeout is 0s, default deadline is expected to be set",
requestURL: "/api/v1/namespaces?timeout=0s",
longRunning: false,
handlerCallCountExpected: 1,
hasDeadlineExpected: true,
deadlineExpected: requestTimeoutMaximum - time.Second, // to account for the delay in verification
statusCodeExpected: http.StatusOK,
},
{
name: "the user does not specify any request timeout, default deadline is expected to be set",
requestURL: "/api/v1/namespaces?timeout=",