From d186af1f4b5ceb8ef74892daffc22ca7ef615815 Mon Sep 17 00:00:00 2001 From: Jake Coffman Date: Thu, 16 Nov 2023 08:39:11 -0600 Subject: [PATCH] fix race --- internal/server/input_test.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/internal/server/input_test.go b/internal/server/input_test.go index 6033889..7d3b346 100644 --- a/internal/server/input_test.go +++ b/internal/server/input_test.go @@ -6,14 +6,11 @@ import ( "github.com/dependabot/cli/internal/model" "net" "net/http" - "sync" "testing" ) func TestInput(t *testing.T) { - wg := sync.WaitGroup{} - wg.Add(1) - var input *model.Input + inputCh := make(chan *model.Input) l, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { @@ -21,11 +18,11 @@ func TestInput(t *testing.T) { } go func() { - input, err = Input(l) + input, err := Input(l) if err != nil { t.Errorf(err.Error()) } - wg.Done() + inputCh <- input }() url := fmt.Sprintf("http://%s", l.Addr().String()) @@ -39,7 +36,7 @@ func TestInput(t *testing.T) { } // Test will hang here if the server does not shut down - wg.Wait() + input := <-inputCh if input.Job.PackageManager != "test" { t.Errorf("expected package manager to be 'test', got '%s'", input.Job.PackageManager)