(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…