Skip to content

Commit

Permalink
fix race
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoffman committed Nov 16, 2023
1 parent cb7ffd3 commit d186af1
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions internal/server/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,23 @@ 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 {
t.Fatal("Failed to create listener: ", err.Error())
}

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())
Expand All @@ -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)
Expand Down

0 comments on commit d186af1

Please sign in to comment.