(proxy connection.OriginProxy)
| 256 | } |
| 257 | |
| 258 | func testProxySSE(proxy connection.OriginProxy) func(t *testing.T) { |
| 259 | return func(t *testing.T) { |
| 260 | var ( |
| 261 | pushCount = 50 |
| 262 | pushFreq = time.Millisecond * 10 |
| 263 | ) |
| 264 | responseWriter := newMockSSERespWriter() |
| 265 | ctx, cancel := context.WithCancel(t.Context()) |
| 266 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("http://localhost:8080%s?freq=%s", hello.SSERoute, pushFreq), nil) |
| 267 | require.NoError(t, err) |
| 268 | |
| 269 | var wg sync.WaitGroup |
| 270 | wg.Add(1) |
| 271 | go func() { |
| 272 | defer wg.Done() |
| 273 | log := zerolog.Nop() |
| 274 | err = proxy.ProxyHTTP(responseWriter, tracing.NewTracedHTTPRequest(req, 0, &log), false) |
| 275 | require.Equal(t, "context canceled", err.Error()) |
| 276 | |
| 277 | require.Equal(t, http.StatusOK, responseWriter.Code) |
| 278 | }() |
| 279 | |
| 280 | for i := 0; i < pushCount; i++ { |
| 281 | line := responseWriter.ReadBytes() |
| 282 | expect := fmt.Sprintf("%d\n\n", i) |
| 283 | require.Equal(t, []byte(expect), line, "Expect to read %v, got %v", expect, line) |
| 284 | } |
| 285 | |
| 286 | cancel() |
| 287 | wg.Wait() |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | // Regression test to guarantee that we always write the contents downstream even if EOF is reached without |
| 292 | // hitting the delimiter |
no test coverage detected