summaryrefslogtreecommitdiff
path: root/integrationtests/harness.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-21 20:16:19 +0200
committerPaul Buetow <paul@buetow.org>2026-02-21 20:18:41 +0200
commite51b8571bc192e7122f25a3d05a6407dfa8a6998 (patch)
tree81e7e1fbe1c9e0a91d033b1aded00b4273502313 /integrationtests/harness.go
parent2f0ac27ec92840cab408e5f5a71d225be070cc0f (diff)
Add ior crash/timeout harness tests (task 343)
- Add waitBoth unit tests: ior exit error, ior timeout, both timeout, both succeed — using real processes (true/false/sleep) - Add TestIorCrashReportsError: full harness test with fake ior binary that exits with error, verifying error mentions 'ior' and workload PID is returned - Add TestIorStartFailureCleansUpWorkload: verifies workload process is killed when ior binary doesn't exist, checking with signal 0 - Refactor waitBoth to accept grace duration parameter for testability (production code passes iorShutdownGrace, tests use 500ms) - Fix pipe drain in startWorkload: drain remaining stdout after reading PID so cmd.Wait() doesn't block on pending I/O - Add writeScript helper to helpers_test.go for creating fake binaries Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019c8162-c1cf-7612-b8f5-84c61e3d2021
Diffstat (limited to 'integrationtests/harness.go')
-rw-r--r--integrationtests/harness.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/integrationtests/harness.go b/integrationtests/harness.go
index 7edde44..fde52e6 100644
--- a/integrationtests/harness.go
+++ b/integrationtests/harness.go
@@ -3,6 +3,7 @@ package integrationtests
import (
"bufio"
"fmt"
+ "io"
"os"
"os/exec"
"path/filepath"
@@ -41,7 +42,7 @@ func (h *TestHarness) Run(scenario string, duration int) (TestResult, int, error
return TestResult{}, workloadPID, err
}
- workloadErr, iorErr := waitBoth(workloadCmd, iorCmd, duration)
+ workloadErr, iorErr := waitBoth(workloadCmd, iorCmd, duration, iorShutdownGrace)
if iorErr != nil {
return TestResult{}, workloadPID, fmt.Errorf("ior: %w", iorErr)
@@ -92,6 +93,8 @@ func (h *TestHarness) startWorkload(scenario string) (*exec.Cmd, int, error) {
} else {
errCh <- fmt.Errorf("workload produced no output")
}
+ // Drain remaining pipe data so cmd.Wait() does not block.
+ io.Copy(io.Discard, stdout) //nolint:errcheck
}()
select {
@@ -132,14 +135,14 @@ func (h *TestHarness) startIor(pid int, scenario string, duration int) (*exec.Cm
// waitBoth waits for both the workload and ior commands concurrently.
// If ior does not finish within duration + grace period, it is killed.
-func waitBoth(workloadCmd, iorCmd *exec.Cmd, duration int) (workloadErr, iorErr error) {
+func waitBoth(workloadCmd, iorCmd *exec.Cmd, duration int, grace time.Duration) (workloadErr, iorErr error) {
workloadDone := make(chan error, 1)
iorDone := make(chan error, 1)
go func() { workloadDone <- workloadCmd.Wait() }()
go func() { iorDone <- iorCmd.Wait() }()
- timeout := time.After(time.Duration(duration)*time.Second + iorShutdownGrace)
+ timeout := time.After(time.Duration(duration)*time.Second + grace)
for workloadDone != nil || iorDone != nil {
select {