(t *testing.T)
| 107 | } |
| 108 | |
| 109 | func TestReadTimeoutSocketClosed(t *testing.T) { |
| 110 | backend := startTestServer([]byte("backend reply"), 0, func(*http.Request) {}) |
| 111 | defer backend.Close() |
| 112 | |
| 113 | doc := fmt.Sprintf(` |
| 114 | r1: Path("/timeout") -> readTimeout("10ms") -> status(201) -> "%s"; |
| 115 | r2: Path("/ok") -> status(200) -> inlineContent("OK") -> <shunt> |
| 116 | `, backend.URL) |
| 117 | |
| 118 | tp, err := newTestProxy(doc, FlagsNone) |
| 119 | if err != nil { |
| 120 | t.Fatal(err) |
| 121 | } |
| 122 | defer tp.close() |
| 123 | |
| 124 | ps := httptest.NewServer(tp.proxy) |
| 125 | defer ps.Close() |
| 126 | |
| 127 | addr := ps.Listener.Addr().String() |
| 128 | |
| 129 | readResp := func(conn net.Conn) *http.Response { |
| 130 | t.Helper() |
| 131 | resp, err := http.ReadResponse(bufio.NewReader(conn), nil) |
| 132 | if err != nil { |
| 133 | t.Fatalf("Failed to read response: %v", err) |
| 134 | } |
| 135 | |
| 136 | _, err = io.ReadAll(resp.Body) |
| 137 | if err != nil { |
| 138 | t.Fatalf("Failed to read response body: %v", err) |
| 139 | } |
| 140 | resp.Body.Close() |
| 141 | |
| 142 | return resp |
| 143 | } |
| 144 | |
| 145 | // Verify both routes return their configured status codes (normal client). |
| 146 | for _, tc := range []struct { |
| 147 | path string |
| 148 | want int |
| 149 | }{ |
| 150 | {"/timeout", http.StatusCreated}, |
| 151 | {"/ok", http.StatusOK}, |
| 152 | } { |
| 153 | resp, err := ps.Client().Get("http://" + addr + tc.path) |
| 154 | if err != nil { |
| 155 | t.Fatalf("GET %s: %v", tc.path, err) |
| 156 | } |
| 157 | resp.Body.Close() |
| 158 | if resp.StatusCode != tc.want { |
| 159 | t.Errorf("GET %s: got %d, want %d", tc.path, resp.StatusCode, tc.want) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | postConn, err := net.Dial("tcp", addr) |
| 164 | if err != nil { |
| 165 | t.Fatalf("dial post conn: %v", err) |
| 166 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…