Skip to content

Commit

Permalink
refactor: enhance IPC handling in task runner tests
Browse files Browse the repository at this point in the history
- Updated IPC reader initialization in runner_test.go to use a channel for signaling readiness, improving synchronization.
- Added error logging when writing to the pipe to enhance traceability during tests.
- These changes improve the reliability and clarity of the test setup for the task runner.
  • Loading branch information
Marvin Zhang committed Jan 3, 2025
1 parent ff5cd32 commit 37d77f7
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions core/task/handler/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,17 @@ func TestRunner(t *testing.T) {
defer pw.Close()
runner.stdoutPipe = pr

// Start IPC reader
go runner.startIPCReader()
// Create a channel to signal that the reader is ready
readerReady := make(chan struct{})

// Start IPC reader with ready signal
go func() {
close(readerReady) // Signal that reader is ready
runner.startIPCReader()
}()

// Wait for reader to be ready
<-readerReady

// Test cases
testCases := []struct {
Expand Down Expand Up @@ -390,8 +399,17 @@ func TestRunner(t *testing.T) {
defer pw.Close()
runner.stdoutPipe = pr

// Start IPC reader
go runner.startIPCReader()
// Create a channel to signal that the reader is ready
readerReady := make(chan struct{})

// Start IPC reader with ready signal
go func() {
close(readerReady) // Signal that reader is ready
runner.startIPCReader()
}()

// Wait for reader to be ready
<-readerReady

// Test cases for invalid data
testCases := []struct {
Expand Down Expand Up @@ -431,7 +449,9 @@ func TestRunner(t *testing.T) {
// Write test message to pipe
go func() {
_, err := fmt.Fprintln(pw, tc.message)
assert.NoError(t, err)
if err != nil {
log.Errorf("failed to write to pipe: %v", err)
}
}()

// Wait briefly to ensure no processing occurs
Expand Down

0 comments on commit 37d77f7

Please sign in to comment.