...

Source file src/github.com/redis/go-redis/v9/internal/pool/conn_check_test.go

Documentation: github.com/redis/go-redis/v9/internal/pool

     1  //go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos
     2  
     3  package pool
     4  
     5  import (
     6  	"net"
     7  	"net/http/httptest"
     8  	"time"
     9  
    10  	. "github.com/bsm/ginkgo/v2"
    11  	. "github.com/bsm/gomega"
    12  )
    13  
    14  var _ = Describe("tests conn_check with real conns", func() {
    15  	var ts *httptest.Server
    16  	var conn net.Conn
    17  	var err error
    18  
    19  	BeforeEach(func() {
    20  		ts = httptest.NewServer(nil)
    21  		conn, err = net.DialTimeout(ts.Listener.Addr().Network(), ts.Listener.Addr().String(), time.Second)
    22  		Expect(err).NotTo(HaveOccurred())
    23  	})
    24  
    25  	AfterEach(func() {
    26  		ts.Close()
    27  	})
    28  
    29  	It("good conn check", func() {
    30  		Expect(connCheck(conn)).NotTo(HaveOccurred())
    31  
    32  		Expect(conn.Close()).NotTo(HaveOccurred())
    33  		Expect(connCheck(conn)).To(HaveOccurred())
    34  	})
    35  
    36  	It("bad conn check", func() {
    37  		Expect(conn.Close()).NotTo(HaveOccurred())
    38  		Expect(connCheck(conn)).To(HaveOccurred())
    39  	})
    40  
    41  	It("check conn deadline", func() {
    42  		Expect(conn.SetDeadline(time.Now())).NotTo(HaveOccurred())
    43  		time.Sleep(time.Millisecond * 10)
    44  		Expect(connCheck(conn)).NotTo(HaveOccurred())
    45  		Expect(conn.Close()).NotTo(HaveOccurred())
    46  	})
    47  })
    48  

View as plain text