|
9 | 9 | "net" |
10 | 10 | "net/http" |
11 | 11 | "net/http/httptest" |
| 12 | + "strings" |
12 | 13 | "sync" |
13 | 14 | "testing" |
14 | 15 | "time" |
@@ -138,6 +139,7 @@ func TestProxySingleOrigin(t *testing.T) { |
138 | 139 | t.Run("testProxyHTTP", testProxyHTTP(proxy)) |
139 | 140 | t.Run("testProxyWebsocket", testProxyWebsocket(proxy)) |
140 | 141 | t.Run("testProxySSE", testProxySSE(proxy)) |
| 142 | + t.Run("testProxySSEAllData", testProxySSEAllData(proxy)) |
141 | 143 | cancel() |
142 | 144 | wg.Wait() |
143 | 145 | } |
@@ -256,6 +258,21 @@ func testProxySSE(proxy connection.OriginProxy) func(t *testing.T) { |
256 | 258 | } |
257 | 259 | } |
258 | 260 |
|
| 261 | +// Regression test to guarantee that we always write the contents downstream even if EOF is reached without |
| 262 | +// hitting the delimiter |
| 263 | +func testProxySSEAllData(proxy *Proxy) func(t *testing.T) { |
| 264 | + return func(t *testing.T) { |
| 265 | + eyeballReader := io.NopCloser(strings.NewReader("data\r\r")) |
| 266 | + responseWriter := newMockSSERespWriter() |
| 267 | + |
| 268 | + // responseWriter uses an unbuffered channel, so we call in a different go-routine |
| 269 | + go proxy.writeEventStream(responseWriter, eyeballReader) |
| 270 | + |
| 271 | + result := string(<-responseWriter.writeNotification) |
| 272 | + require.Equal(t, "data\r\r", result) |
| 273 | + } |
| 274 | +} |
| 275 | + |
259 | 276 | func TestProxyMultipleOrigins(t *testing.T) { |
260 | 277 | api := httptest.NewServer(mockAPI{}) |
261 | 278 | defer api.Close() |
@@ -447,7 +464,7 @@ func TestConnections(t *testing.T) { |
447 | 464 | // eyeball connection type. |
448 | 465 | connectionType connection.Type |
449 | 466 |
|
450 | | - //requestheaders to be sent in the call to proxy.Proxy |
| 467 | + // requestheaders to be sent in the call to proxy.Proxy |
451 | 468 | requestHeaders http.Header |
452 | 469 | } |
453 | 470 |
|
@@ -508,7 +525,7 @@ func TestConnections(t *testing.T) { |
508 | 525 | args: args{ |
509 | 526 | ingressServiceScheme: "ws://", |
510 | 527 | originService: runEchoWSService, |
511 | | - //eyeballResponseWriter gets set after roundtrip dial. |
| 528 | + // eyeballResponseWriter gets set after roundtrip dial. |
512 | 529 | eyeballRequestBody: newPipedWSRequestBody([]byte("test3")), |
513 | 530 | warpRoutingService: ingress.NewWarpRoutingService(), |
514 | 531 | requestHeaders: map[string][]string{ |
|
0 commit comments