2022-03-20 20:06:47 +03:00
|
|
|
//go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos
|
|
|
|
|
|
|
|
package pool
|
|
|
|
|
|
|
|
import (
|
2024-07-12 06:16:21 +03:00
|
|
|
"crypto/tls"
|
2022-03-20 20:06:47 +03:00
|
|
|
"net"
|
|
|
|
"net/http/httptest"
|
2024-07-19 10:15:46 +03:00
|
|
|
"syscall"
|
2022-03-20 20:06:47 +03:00
|
|
|
"time"
|
|
|
|
|
2023-01-27 18:00:49 +03:00
|
|
|
. "github.com/bsm/ginkgo/v2"
|
|
|
|
. "github.com/bsm/gomega"
|
2022-03-20 20:06:47 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("tests conn_check with real conns", func() {
|
|
|
|
var ts *httptest.Server
|
|
|
|
var conn net.Conn
|
2024-07-12 06:16:21 +03:00
|
|
|
var tlsConn *tls.Conn
|
2024-07-19 10:15:46 +03:00
|
|
|
var sysConn syscall.Conn
|
|
|
|
var tlsSysConn syscall.Conn
|
2022-03-20 20:06:47 +03:00
|
|
|
var err error
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
ts = httptest.NewServer(nil)
|
|
|
|
conn, err = net.DialTimeout(ts.Listener.Addr().Network(), ts.Listener.Addr().String(), time.Second)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2024-07-19 10:15:46 +03:00
|
|
|
sysConn = conn.(syscall.Conn)
|
2024-07-12 06:16:21 +03:00
|
|
|
tlsTestServer := httptest.NewUnstartedServer(nil)
|
|
|
|
tlsTestServer.StartTLS()
|
|
|
|
tlsConn, err = tls.DialWithDialer(&net.Dialer{Timeout: time.Second}, tlsTestServer.Listener.Addr().Network(), tlsTestServer.Listener.Addr().String(), &tls.Config{InsecureSkipVerify: true})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2024-07-19 10:15:46 +03:00
|
|
|
tlsSysConn = tlsConn.NetConn().(syscall.Conn)
|
2022-03-20 20:06:47 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
ts.Close()
|
|
|
|
})
|
|
|
|
|
|
|
|
It("good conn check", func() {
|
2024-07-19 10:15:46 +03:00
|
|
|
Expect(connCheck(sysConn)).NotTo(HaveOccurred())
|
2022-03-20 20:06:47 +03:00
|
|
|
|
|
|
|
Expect(conn.Close()).NotTo(HaveOccurred())
|
2024-07-19 10:15:46 +03:00
|
|
|
Expect(connCheck(sysConn)).To(HaveOccurred())
|
2022-03-20 20:06:47 +03:00
|
|
|
})
|
|
|
|
|
2024-07-12 06:16:21 +03:00
|
|
|
It("good tls conn check", func() {
|
2024-07-19 10:15:46 +03:00
|
|
|
Expect(connCheck(tlsSysConn)).NotTo(HaveOccurred())
|
2024-07-12 06:16:21 +03:00
|
|
|
|
|
|
|
Expect(tlsConn.Close()).NotTo(HaveOccurred())
|
2024-07-19 10:15:46 +03:00
|
|
|
Expect(connCheck(tlsSysConn)).To(HaveOccurred())
|
2024-07-12 06:16:21 +03:00
|
|
|
})
|
|
|
|
|
2022-03-20 20:06:47 +03:00
|
|
|
It("bad conn check", func() {
|
|
|
|
Expect(conn.Close()).NotTo(HaveOccurred())
|
2024-07-19 10:15:46 +03:00
|
|
|
Expect(connCheck(sysConn)).To(HaveOccurred())
|
2022-03-20 20:06:47 +03:00
|
|
|
})
|
|
|
|
|
2024-07-12 06:16:21 +03:00
|
|
|
It("bad tls conn check", func() {
|
|
|
|
Expect(tlsConn.Close()).NotTo(HaveOccurred())
|
2024-07-19 10:15:46 +03:00
|
|
|
Expect(connCheck(tlsSysConn)).To(HaveOccurred())
|
2024-07-12 06:16:21 +03:00
|
|
|
})
|
|
|
|
|
2022-03-20 20:06:47 +03:00
|
|
|
It("check conn deadline", func() {
|
|
|
|
Expect(conn.SetDeadline(time.Now())).NotTo(HaveOccurred())
|
|
|
|
time.Sleep(time.Millisecond * 10)
|
2024-07-19 10:15:46 +03:00
|
|
|
Expect(connCheck(sysConn)).To(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(conn.SetDeadline(time.Now().Add(time.Minute))).NotTo(HaveOccurred())
|
|
|
|
time.Sleep(time.Millisecond * 10)
|
|
|
|
Expect(connCheck(sysConn)).NotTo(HaveOccurred())
|
2022-03-20 20:06:47 +03:00
|
|
|
Expect(conn.Close()).NotTo(HaveOccurred())
|
|
|
|
})
|
|
|
|
})
|