diff --git a/dsl/client.go b/dsl/client.go index fbabfbca9..1fb8d9b3c 100644 --- a/dsl/client.go +++ b/dsl/client.go @@ -12,6 +12,7 @@ import ( "regexp" "strconv" "strings" + "sync" "time" "github.com/pact-foundation/pact-go/client" @@ -182,7 +183,7 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid } // Buffered channel: wait for all reading to complete - done := make(chan struct{}, 2) + var wg sync.WaitGroup verifications := []string{} var stdErr strings.Builder @@ -191,21 +192,23 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid // See https://github.com/pact-foundation/pact-go/issues/88#issuecomment-404686337 stdOutScanner := bufio.NewScanner(stdOutPipe) go func() { + wg.Add(1) for stdOutScanner.Scan() { verifications = append(verifications, stdOutScanner.Text()) } - done <- struct{}{} + wg.Done() }() // Scrape errors stdErrScanner := bufio.NewScanner(stdErrPipe) go func() { + wg.Add(1) for stdErrScanner.Scan() { stdErr.WriteString(fmt.Sprintf("%s\n", stdErrScanner.Text())) } - done <- struct{}{} + wg.Done() }() err = cmd.Start() @@ -214,9 +217,8 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid } // Wait for watch goroutine before Cmd.Wait(), race condition! - <-done - err = cmd.Wait() + wg.Wait() var verification types.ProviderVerifierResponse for _, v := range verifications {