From cebdb5f6fa2afd66847b92704eda14f92abd08e4 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Thu, 30 Jan 2025 13:39:28 -0800 Subject: [PATCH] test/runner: interrupt S/R loop if the test has been signalled When a test exceed a specified timeout and receives SIGTERM and then it has 15 seconds to complete all operations and collect all logs. If it doesn't exit in 15 seconds, it will be killed by SIGKILL. PiperOrigin-RevId: 721504425 --- test/runner/main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/runner/main.go b/test/runner/main.go index d651770717..73b06b214c 100644 --- a/test/runner/main.go +++ b/test/runner/main.go @@ -27,6 +27,7 @@ import ( "os/signal" "path/filepath" "strings" + "sync/atomic" "syscall" "testing" "time" @@ -495,6 +496,7 @@ func runRunsc(tc *gtest.TestCase, spec *specs.Spec) error { cmd.Stderr = os.Stderr sig := make(chan os.Signal, 1) defer close(sig) + signalled := atomic.Bool{} signal.Notify(sig, unix.SIGTERM) defer signal.Stop(sig) go func() { @@ -502,6 +504,7 @@ func runRunsc(tc *gtest.TestCase, spec *specs.Spec) error { if !ok { return } + signalled.Store(true) log.Warningf("%s: Got signal: %v", name, s) done := make(chan bool, 1) dArgs := append([]string{}, args...) @@ -541,6 +544,9 @@ func runRunsc(tc *gtest.TestCase, spec *specs.Spec) error { // Restore the sandbox with the previous state file. for i := 1; ; i++ { + if signalled.Load() { + return fmt.Errorf("timeout") + } // Check if the latest state file is valid. If the file // is empty, delete it and exit the loop. isEmpty, err := deleteIfEmptyFile(dirs[i-1])