mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
refactor: enhance IPC handling in task runner tests
- 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.
This commit is contained in:
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user