aboutsummaryrefslogtreecommitdiff
path: root/client_test.go
diff options
context:
space:
mode:
authorGravatar Erik Dubbelboer <erik@dubbelboer.com> 2020-06-16 11:58:07 +0200
committerGravatar GitHub <noreply@github.com> 2020-06-16 11:58:07 +0200
commit9dd7979b2e0276281f6d2b2de817f1bdfb88dd3b (patch)
tree5742766ae5d74a237339e4d03b72f27e1c330e88 /client_test.go
parentFixed bug which prevents cached FS files from being updated (diff)
downloadfasthttp-9dd7979b2e0276281f6d2b2de817f1bdfb88dd3b.tar.gz
fasthttp-9dd7979b2e0276281f6d2b2de817f1bdfb88dd3b.tar.bz2
fasthttp-9dd7979b2e0276281f6d2b2de817f1bdfb88dd3b.zip
Restart PipelineClient worker on error (#834)
Diffstat (limited to 'client_test.go')
-rw-r--r--client_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/client_test.go b/client_test.go
index 63c7f7e..3088181 100644
--- a/client_test.go
+++ b/client_test.go
@@ -20,6 +20,60 @@ import (
"github.com/valyala/fasthttp/fasthttputil"
)
+func TestPipelineClientIssue832(t *testing.T) {
+ t.Parallel()
+
+ ln := fasthttputil.NewInmemoryListener()
+
+ req := AcquireRequest()
+ defer ReleaseRequest(req)
+ req.SetHost("example.com")
+
+ res := AcquireResponse()
+ defer ReleaseResponse(res)
+
+ client := PipelineClient{
+ Dial: func(addr string) (net.Conn, error) {
+ return ln.Dial()
+ },
+ ReadTimeout: time.Millisecond * 10,
+ Logger: &testLogger{}, // Ignore log output.
+ }
+
+ attempts := 10
+ go func() {
+ for i := 0; i < attempts; i++ {
+ c, err := ln.Accept()
+ if err != nil {
+ t.Error(err)
+ }
+ if c != nil {
+ go func() {
+ time.Sleep(time.Millisecond * 50)
+ c.Close()
+ }()
+ }
+ }
+ }()
+
+ done := make(chan int)
+ go func() {
+ defer close(done)
+
+ for i := 0; i < attempts; i++ {
+ if err := client.Do(req, res); err == nil {
+ t.Error("error expected")
+ }
+ }
+ }()
+
+ select {
+ case <-time.After(time.Second):
+ t.Fatal("PipelineClient did not restart worker")
+ case <-done:
+ }
+}
+
func TestClientInvalidURI(t *testing.T) {
t.Parallel()