diff --git a/transformation_test/transformation_test.go b/transformation_test/transformation_test.go index f8b5cce07b..bb55bf1b2f 100644 --- a/transformation_test/transformation_test.go +++ b/transformation_test/transformation_test.go @@ -444,9 +444,24 @@ func (transformationConfig transformationTest) runOTelTestInner(t *testing.T, na } var errors []any + var exitErr error // Read from stderr until EOF and put any errors in `errors`. eg.Go(func() error { + // Wait for the process to exit. + defer eg.Go(func() error { + if err := cmd.Wait(); err != nil { + if _, ok := err.(*exec.ExitError); ok { + exitErr = err + t.Logf("process terminated with error: %v", err) + } else { + return fmt.Errorf("process failed: %w", err) + } + } + cancel() + return nil + }) + consumingCount := 0 r := bufio.NewReader(stderr) d := json.NewDecoder(r) @@ -498,6 +513,7 @@ func (transformationConfig transformationTest) runOTelTestInner(t *testing.T, na } } }) + // Read and sanitize requests. eg.Go(func() error { for r := range requestCh { @@ -506,21 +522,6 @@ func (transformationConfig transformationTest) runOTelTestInner(t *testing.T, na return nil }) - var exitErr error - // Wait for the process to exit. - eg.Go(func() error { - if err := cmd.Wait(); err != nil { - if _, ok := err.(*exec.ExitError); ok { - exitErr = err - t.Logf("process terminated with error: %v", err) - } else { - return fmt.Errorf("process failed: %w", err) - } - } - cancel() - return nil - }) - if err := eg.Wait(); err != nil { t.Errorf("errgroup failed: %v", err) }