From 1bf710ffdcc65301f3d0ffc45b45ab2961630b00 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 9 Apr 2024 15:27:25 -0700 Subject: [PATCH] Fix unit tests. - Add a short sleep to startEvent stream to mitigate race condition. expectResponse() already has one. - Add a required Host: header to the HTTP/1.1 GET request --- eventsource_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eventsource_test.go b/eventsource_test.go index abb48c7..0d519db 100644 --- a/eventsource_test.go +++ b/eventsource_test.go @@ -70,13 +70,14 @@ func read(t *testing.T, c net.Conn) []byte { func startEventStream(t *testing.T, e *testEnv) (net.Conn, []byte) { url := e.server.URL - t.Log("open connection") + t.Logf("open connection to %s", url) conn, err := net.Dial("tcp", strings.Replace(url, "http://", "", 1)) checkError(t, err) t.Log("send GET request to the connection") - _, err = conn.Write([]byte("GET / HTTP/1.1\n\n")) + _, err = conn.Write([]byte("GET / HTTP/1.1\nHost: localhost\n\n")) checkError(t, err) + time.Sleep(100 * time.Millisecond) resp := read(t, conn) t.Logf("got response: \n%s", resp) return conn, resp