From d249ef1a3bc17069c04a649ec1f6d38ed3343de7 Mon Sep 17 00:00:00 2001 From: Cooper Oh Date: Fri, 19 Jul 2024 00:32:35 +0900 Subject: [PATCH] use done chan for waiting pipe --- client_server_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/client_server_test.go b/client_server_test.go index 5a2113f..2dbd7e6 100644 --- a/client_server_test.go +++ b/client_server_test.go @@ -109,17 +109,16 @@ func (s *cstProxyServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { _, _ = fmt.Fprintf(conn, "HTTP/1.1 200 Connection established\r\n\r\n") - wg := sync.WaitGroup{} - wg.Add(2) + done := make(chan struct{}, 2) go func() { - defer wg.Done() _, _ = io.Copy(upstream, conn) + done <- struct{}{} }() go func() { - defer wg.Done() _, _ = io.Copy(conn, upstream) + done <- struct{}{} }() - wg.Wait() + <-done } func newProxyServer() *httptest.Server {