From 4ac68711cd9c3d54b6b474ef03a4225d62e03d3c Mon Sep 17 00:00:00 2001 From: Nuno Diegues Date: Thu, 1 Sep 2022 15:41:33 +0100 Subject: [PATCH] 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 --- proxy/proxy_test.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/proxy/proxy_test.go b/proxy/proxy_test.go index 5407acaa..384298c3 100644 --- a/proxy/proxy_test.go +++ b/proxy/proxy_test.go @@ -130,6 +130,10 @@ func (w *mockSSERespWriter) Write(data []byte) (int, error) { return len(data), nil } +func (w *mockSSERespWriter) WriteString(str string) (int, error) { + return w.Write([]byte(str)) +} + func (w *mockSSERespWriter) ReadBytes() []byte { return <-w.writeNotification } @@ -156,7 +160,6 @@ func TestProxySingleOrigin(t *testing.T) { t.Run("testProxyHTTP", testProxyHTTP(proxy)) t.Run("testProxyWebsocket", testProxyWebsocket(proxy)) t.Run("testProxySSE", testProxySSE(proxy)) - t.Run("testProxySSEAllData", testProxySSEAllData(proxy)) cancel() } @@ -276,17 +279,15 @@ func testProxySSE(proxy connection.OriginProxy) func(t *testing.T) { // Regression test to guarantee that we always write the contents downstream even if EOF is reached without // hitting the delimiter -func testProxySSEAllData(proxy *Proxy) func(t *testing.T) { - return func(t *testing.T) { - eyeballReader := io.NopCloser(strings.NewReader("data\r\r")) - responseWriter := newMockSSERespWriter() +func TestProxySSEAllData(t *testing.T) { + eyeballReader := io.NopCloser(strings.NewReader("data\r\r")) + responseWriter := newMockSSERespWriter() - // responseWriter uses an unbuffered channel, so we call in a different go-routine - go cfio.Copy(responseWriter, eyeballReader) + // responseWriter uses an unbuffered channel, so we call in a different go-routine + go cfio.Copy(responseWriter, eyeballReader) - result := string(<-responseWriter.writeNotification) - require.Equal(t, "data\r\r", result) - } + result := string(<-responseWriter.writeNotification) + require.Equal(t, "data\r\r", result) } func TestProxyMultipleOrigins(t *testing.T) {