Skip to content

Commit 4ac6871

Browse files
committed
TUN-6725: Fix testProxySSEAllData
This test was failing on Windows. We did not catch it before because our TeamCity Windows builds were ignoring failed unit tests: TUN-6727 - the fix is implementing WriteString for mockSSERespWriter - reason is because cfio.Copy was calling that, and not Write method, thus not triggering the usage of the channel for the test to continue - mockSSERespWriter was providing a valid implementation of WriteString via ResponseRecorder, which it implements via the embedded mockHTTPRespWriter - it is not clear why this only happened on Windows - changed it to be a top-level test since it did not share any code with other sub-tests in the same top-level test
1 parent 075ac1a commit 4ac6871

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

proxy/proxy_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ func (w *mockSSERespWriter) Write(data []byte) (int, error) {
130130
return len(data), nil
131131
}
132132

133+
func (w *mockSSERespWriter) WriteString(str string) (int, error) {
134+
return w.Write([]byte(str))
135+
}
136+
133137
func (w *mockSSERespWriter) ReadBytes() []byte {
134138
return <-w.writeNotification
135139
}
@@ -156,7 +160,6 @@ func TestProxySingleOrigin(t *testing.T) {
156160
t.Run("testProxyHTTP", testProxyHTTP(proxy))
157161
t.Run("testProxyWebsocket", testProxyWebsocket(proxy))
158162
t.Run("testProxySSE", testProxySSE(proxy))
159-
t.Run("testProxySSEAllData", testProxySSEAllData(proxy))
160163
cancel()
161164
}
162165

@@ -276,17 +279,15 @@ func testProxySSE(proxy connection.OriginProxy) func(t *testing.T) {
276279

277280
// Regression test to guarantee that we always write the contents downstream even if EOF is reached without
278281
// hitting the delimiter
279-
func testProxySSEAllData(proxy *Proxy) func(t *testing.T) {
280-
return func(t *testing.T) {
281-
eyeballReader := io.NopCloser(strings.NewReader("data\r\r"))
282-
responseWriter := newMockSSERespWriter()
282+
func TestProxySSEAllData(t *testing.T) {
283+
eyeballReader := io.NopCloser(strings.NewReader("data\r\r"))
284+
responseWriter := newMockSSERespWriter()
283285

284-
// responseWriter uses an unbuffered channel, so we call in a different go-routine
285-
go cfio.Copy(responseWriter, eyeballReader)
286+
// responseWriter uses an unbuffered channel, so we call in a different go-routine
287+
go cfio.Copy(responseWriter, eyeballReader)
286288

287-
result := string(<-responseWriter.writeNotification)
288-
require.Equal(t, "data\r\r", result)
289-
}
289+
result := string(<-responseWriter.writeNotification)
290+
require.Equal(t, "data\r\r", result)
290291
}
291292

292293
func TestProxyMultipleOrigins(t *testing.T) {

0 commit comments

Comments
 (0)