aboutsummaryrefslogtreecommitdiff
path: root/client_test.go
diff options
context:
space:
mode:
authorGravatar Erik Dubbelboer <erik@dubbelboer.com> 2020-09-13 13:58:13 +0200
committerGravatar Erik Dubbelboer <erik@dubbelboer.com> 2020-09-13 13:58:13 +0200
commitae8b65fa6279eb1c654d837612f06894384935b1 (patch)
tree25f2b9d172f39d0b2079aa88d969e3a625cc4fd9 /client_test.go
parentGit commit fix URI parse for urls like host.dm?some/path/to/file (#866) (diff)
downloadfasthttp-ae8b65fa6279eb1c654d837612f06894384935b1.tar.gz
fasthttp-ae8b65fa6279eb1c654d837612f06894384935b1.tar.bz2
fasthttp-ae8b65fa6279eb1c654d837612f06894384935b1.zip
Add Client.CloseIdleConnections()
Diffstat (limited to 'client_test.go')
-rw-r--r--client_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/client_test.go b/client_test.go
index bb04cef..95b102a 100644
--- a/client_test.go
+++ b/client_test.go
@@ -20,6 +20,50 @@ import (
"github.com/valyala/fasthttp/fasthttputil"
)
+func TestCloseIdleConnections(t *testing.T) {
+ ln := fasthttputil.NewInmemoryListener()
+
+ s := &Server{
+ Handler: func(ctx *RequestCtx) {
+ },
+ }
+ go func() {
+ if err := s.Serve(ln); err != nil {
+ t.Error(err)
+ }
+ }()
+
+ c := &Client{
+ Dial: func(addr string) (net.Conn, error) {
+ return ln.Dial()
+ },
+ }
+
+ if _, _, err := c.Get(nil, "http://google.com"); err != nil {
+ t.Fatal(err)
+ }
+
+ connsLen := func() int {
+ c.mLock.Lock()
+ defer c.mLock.Unlock()
+
+ c.m["google.com"].connsLock.Lock()
+ defer c.m["google.com"].connsLock.Unlock()
+
+ return len(c.m["google.com"].conns)
+ }
+
+ if conns := connsLen(); conns > 1 {
+ t.Errorf("expected 1 conns got %d", conns)
+ }
+
+ c.CloseIdleConnections()
+
+ if conns := connsLen(); conns > 0 {
+ t.Errorf("expected 0 conns got %d", conns)
+ }
+}
+
func TestPipelineClientIssue832(t *testing.T) {
t.Parallel()