Skip to content

Commit 4a1e993

Browse files
avagingvisor-bot
authored andcommitted
test/runner: interrupt S/R loop if the test has been signalled
When a test exceeds the specified timeout and receives SIGTERM, it has 15 seconds to complete all operations and collect all logs. If it doesn't exit within 15 seconds, it will be killed by SIGKILL. PiperOrigin-RevId: 761244166
1 parent 1c1fa72 commit 4a1e993

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

test/runner/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"os/signal"
2828
"path/filepath"
2929
"strings"
30+
"sync/atomic"
3031
"syscall"
3132
"testing"
3233
"time"
@@ -491,13 +492,15 @@ func runRunsc(tc *gtest.TestCase, spec *specs.Spec) error {
491492
cmd.Stderr = os.Stderr
492493
sig := make(chan os.Signal, 1)
493494
defer close(sig)
495+
signalled := atomic.Bool{}
494496
signal.Notify(sig, unix.SIGTERM)
495497
defer signal.Stop(sig)
496498
go func() {
497499
s, ok := <-sig
498500
if !ok {
499501
return
500502
}
503+
signalled.Store(true)
501504
log.Warningf("%s: Got signal: %v", name, s)
502505
done := make(chan bool, 1)
503506
dArgs := append([]string{}, args...)
@@ -537,6 +540,9 @@ func runRunsc(tc *gtest.TestCase, spec *specs.Spec) error {
537540

538541
// Restore the sandbox with the previous state file.
539542
for i := 1; ; i++ {
543+
if signalled.Load() {
544+
return fmt.Errorf("timeout")
545+
}
540546
// Check if the latest state file is valid. If the file
541547
// is empty, delete it and exit the loop.
542548
isEmpty, err := deleteIfEmptyFile(dirs[i-1])

0 commit comments

Comments
 (0)