summaryrefslogtreecommitdiff
path: root/integrationtests/harness.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-04 20:19:37 +0200
committerPaul Buetow <paul@buetow.org>2026-03-04 20:20:25 +0200
commit96225fb6159212a8851043a08d781aba721b4e78 (patch)
treeabebcaa74594886c3f130a6c03b7aa2691849cf5 /integrationtests/harness.go
parent1f8b6804f69632914ad0ab64892021315e99f421 (diff)
Fix Go mistake findings and stabilize integration timing
Diffstat (limited to 'integrationtests/harness.go')
-rw-r--r--integrationtests/harness.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/integrationtests/harness.go b/integrationtests/harness.go
index a8a73d0..17ae994 100644
--- a/integrationtests/harness.go
+++ b/integrationtests/harness.go
@@ -102,6 +102,9 @@ func (h *TestHarness) startWorkload(scenario string) (*exec.Cmd, int, error) {
io.Copy(io.Discard, stdout) //nolint:errcheck
}()
+ startupTimer := time.NewTimer(workloadStartupTimeout)
+ defer stopAndDrainTimer(startupTimer)
+
select {
case pid := <-pidCh:
return cmd, pid, nil
@@ -109,7 +112,7 @@ func (h *TestHarness) startWorkload(scenario string) (*exec.Cmd, int, error) {
cmd.Process.Kill()
cmd.Wait()
return nil, 0, err
- case <-time.After(workloadStartupTimeout):
+ case <-startupTimer.C:
cmd.Process.Kill()
cmd.Wait()
return nil, 0, fmt.Errorf("timeout waiting for workload PID")
@@ -151,7 +154,8 @@ func waitBoth(workloadCmd, iorCmd *exec.Cmd, duration int, grace time.Duration)
go func(ch chan error) { ch <- workloadCmd.Wait() }(workloadDone)
go func(ch chan error) { ch <- iorCmd.Wait() }(iorDone)
- timeout := time.After(time.Duration(duration)*time.Second + grace)
+ timeout := time.NewTimer(time.Duration(duration)*time.Second + grace)
+ defer stopAndDrainTimer(timeout)
for workloadDone != nil || iorDone != nil {
select {
@@ -161,7 +165,7 @@ func waitBoth(workloadCmd, iorCmd *exec.Cmd, duration int, grace time.Duration)
case err := <-iorDone:
iorErr = err
iorDone = nil
- case <-timeout:
+ case <-timeout.C:
if iorDone != nil {
iorCmd.Process.Kill()
iorErr = fmt.Errorf("ior timed out")
@@ -178,6 +182,19 @@ func waitBoth(workloadCmd, iorCmd *exec.Cmd, duration int, grace time.Duration)
return
}
+func stopAndDrainTimer(timer *time.Timer) {
+ if timer == nil {
+ return
+ }
+ if timer.Stop() {
+ return
+ }
+ select {
+ case <-timer.C:
+ default:
+ }
+}
+
// findIorZstFile locates the .ior.zst file matching the scenario name in the output directory.
func findIorZstFile(dir, scenario string) (string, error) {
entries, err := os.ReadDir(dir)