From 7b6ab0a315b8b7f9a218e85c4ab71e367e280d0a Mon Sep 17 00:00:00 2001 From: satk0 Date: Mon, 23 Dec 2024 20:09:12 +0100 Subject: [PATCH] Fix this goroutines errors --- .../startup_manager/startup_manager_test.go | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/internal/startup_manager/startup_manager_test.go b/internal/startup_manager/startup_manager_test.go index e15ef81..a392d33 100644 --- a/internal/startup_manager/startup_manager_test.go +++ b/internal/startup_manager/startup_manager_test.go @@ -46,15 +46,19 @@ func TestAppServer(t *testing.T) { }() name := net.JoinHostPort("localhost", strconv.Itoa(cfg.Server.Port)) - go func(t *testing.T) { + errs := make(chan error, 1) + go func() { conn, err := net.DialTimeout("tcp", name, timeout) - if err != nil { - t.Fatalf("unexpected error: %v", err) - } + errs <- err if conn != nil { defer conn.Close() } - }(t) + }() + + err = <-errs + if err != nil { + t.Fatalf("unexpected error: %v", err) + } err = sm.shutdownServer(ctx) if err != nil { @@ -100,15 +104,19 @@ func TestAppServer(t *testing.T) { dialer := net.Dialer{Timeout: timeout} name := net.JoinHostPort("localhost", strconv.Itoa(cfg.Server.Port)) - go func(t *testing.T) { + + errs := make(chan error, 1) + go func() { conn, err := tls.DialWithDialer(&dialer, "tcp", name, tlsConfig) - if err != nil { - t.Fatalf("unexpected error: %v", err) - } + errs <- err if conn != nil { defer conn.Close() } - }(t) + }() + err = <-errs + if err != nil { + t.Fatalf("unexpected error: %v", err) + } err = sm.shutdownServer(ctx) if err != nil {