From 2e691c982e712362e8180c753a733ac00eadc9fe Mon Sep 17 00:00:00 2001 From: l3uddz Date: Fri, 21 Feb 2020 08:45:19 +0000 Subject: [PATCH 1/2] pvr: default timeout retries to 6, 500ms min / 10s max --- pvr/pvr.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pvr/pvr.go b/pvr/pvr.go index c87bb446..569e57a8 100644 --- a/pvr/pvr.go +++ b/pvr/pvr.go @@ -13,14 +13,14 @@ var ( pvrDefaultPageSize = 1000 pvrDefaultTimeout = 120 pvrDefaultRetry = web.Retry{ - MaxAttempts: 5, + MaxAttempts: 6, RetryableStatusCodes: []int{ 504, }, Backoff: backoff.Backoff{ Jitter: true, - Min: 1 * time.Second, - Max: 5 * time.Second, + Min: 500 * time.Millisecond, + Max: 10 * time.Second, }, } ) From ed219c2d0fbcd57bbe7aca8493cd4e5eebaf7bee Mon Sep 17 00:00:00 2001 From: l3uddz Date: Fri, 21 Feb 2020 20:32:39 +0000 Subject: [PATCH 2/2] web: add timeout test --- Makefile | 2 +- utils/web/request_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 utils/web/request_test.go diff --git a/Makefile b/Makefile index 443c839e..8ab17914 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ test-all: test lint .PHONY: test test: ## Run tests @echo "*** go test ***" - go test -cover -mod vendor -v -race ${GO_PACKAGES} + go test -cover -v -race ${GO_PACKAGES} .PHONY: lint lint: check_golangci ## Run linting diff --git a/utils/web/request_test.go b/utils/web/request_test.go new file mode 100644 index 00000000..e7640ec4 --- /dev/null +++ b/utils/web/request_test.go @@ -0,0 +1,20 @@ +package web + +import ( + "os" + "testing" +) + +/* Test Get Response Timeout */ + +func TestGetResponseTimeout(t *testing.T) { + // send request + resp, err := GetResponse(GET, "https://httpbin.davecheney.com/delay/5", 3) + if err != nil && !os.IsTimeout(err) { + t.Errorf("Expected timeout in 3 seconds but got error: %v", err) + return + } else if err == nil { + defer resp.Response().Body.Close() + t.Errorf("Expected timeout in 3 seconds but got no error...") + } +}