MCPcopy
hub / github.com/nextdns/nextdns / TestServeTCPConn_IdleReadTimeout

Function TestServeTCPConn_IdleReadTimeout

proxy/tcp_test.go:10–44  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestServeTCPConn_IdleReadTimeout(t *testing.T) {
11 prev := tcpClientReadTimeout
12 tcpClientReadTimeout = 50 * time.Millisecond
13 t.Cleanup(func() {
14 tcpClientReadTimeout = prev
15 })
16
17 server, client := net.Pipe()
18 defer client.Close()
19
20 bpool := &sync.Pool{
21 New: func() any {
22 return new(tcpBuf)
23 },
24 }
25 inflightRequests := make(chan struct{}, 1)
26 errC := make(chan error, 1)
27
28 go func() {
29 errC <- (Proxy{}).serveTCPConn(server, inflightRequests, bpool)
30 }()
31
32 select {
33 case err := <-errC:
34 if err == nil {
35 t.Fatal("serveTCPConn() err = nil, want timeout error")
36 }
37 case <-time.After(250 * time.Millisecond):
38 t.Fatal("serveTCPConn() did not time out idle client")
39 }
40
41 if got := len(inflightRequests); got != 0 {
42 t.Fatalf("inflightRequests len = %d, want 0", got)
43 }
44}

Callers

nothing calls this directly

Calls 2

serveTCPConnMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…