Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address pipe-read race condition #1834

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions transformation_test/transformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -498,6 +513,7 @@ func (transformationConfig transformationTest) runOTelTestInner(t *testing.T, na
}
}
})

// Read and sanitize requests.
eg.Go(func() error {
for r := range requestCh {
Expand All @@ -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)
}
Expand Down