Fix function test timeout doesnt works (#1539)

This commit is contained in:
Ta-Ching Chen
2020-02-19 17:03:02 +08:00
committed by GitHub
parent 735f9abef7
commit 03ce1e27c7
+11 -2
View File
@@ -24,6 +24,7 @@ import (
"net/url"
"os"
"strings"
"time"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -95,8 +96,16 @@ func (opts *TestSubCommand) do(input cli.Input) error {
functionUrl.RawQuery = query.Encode()
}
ctx, closeCtx := context.WithTimeout(context.Background(), input.Duration(flagkey.FnTestTimeout))
defer closeCtx()
var ctx context.Context
testTimeout := input.Duration(flagkey.FnTestTimeout)
if testTimeout <= 0*time.Second {
ctx = context.Background()
} else {
var closeCtx context.CancelFunc
ctx, closeCtx = context.WithTimeout(context.Background(), input.Duration(flagkey.FnTestTimeout))
defer closeCtx()
}
resp, err := doHTTPRequest(ctx, functionUrl.String(),
input.StringSlice(flagkey.FnTestHeader),