diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2023-09-09 14:28:52 +0200 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2023-09-09 14:28:52 +0200 |
commit | 8cc5539af71f1f944d81365c7bccc2958ded0a7f (patch) | |
tree | 32c0cf44dfc996dd62ff9970ada5df6c2842876d /client_test.go | |
parent | Allow connection close for custom streams (#1603) (diff) | |
download | fasthttp-8cc5539af71f1f944d81365c7bccc2958ded0a7f.tar.gz fasthttp-8cc5539af71f1f944d81365c7bccc2958ded0a7f.tar.bz2 fasthttp-8cc5539af71f1f944d81365c7bccc2958ded0a7f.zip |
Fix various request timeout issuesv1.50.0
A timeout of 0 should timeout immediately. When retrying requests the
timeout should be updated to reflect the already passed time
Fixes https://github.com/valyala/fasthttp/issues/1617
Diffstat (limited to 'client_test.go')
-rw-r--r-- | client_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/client_test.go b/client_test.go index 74b87a2..9ff3bda 100644 --- a/client_test.go +++ b/client_test.go @@ -146,6 +146,46 @@ func TestHostClientNegativeTimeout(t *testing.T) { ln.Close() } +func TestDoDeadlineRetry(t *testing.T) { + t.Parallel() + + tries := 0 + done := make(chan struct{}) + + ln := fasthttputil.NewInmemoryListener() + go func() { + for { + c, err := ln.Accept() + if err != nil { + close(done) + break + } + tries++ + br := bufio.NewReader(c) + (&RequestHeader{}).Read(br) //nolint:errcheck + (&Request{}).readBodyStream(br, 0, false, false) //nolint:errcheck + time.Sleep(time.Millisecond * 60) + c.Close() + } + }() + c := &HostClient{ + Dial: func(addr string) (net.Conn, error) { + return ln.Dial() + }, + } + req := AcquireRequest() + req.Header.SetMethod(MethodGet) + req.SetRequestURI("http://example.com") + if err := c.DoDeadline(req, nil, time.Now().Add(time.Millisecond*100)); err != ErrTimeout { + t.Fatalf("expected ErrTimeout error got: %+v", err) + } + ln.Close() + <-done + if tries != 2 { + t.Fatalf("expected 2 tries got %d", tries) + } +} + func TestPipelineClientIssue832(t *testing.T) { t.Parallel() |