Skip to content

Commit

Permalink
test/runner: interrupt S/R loop if the test has been signalled
Browse files Browse the repository at this point in the history
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
  • Loading branch information
avagin authored and gvisor-bot committed Feb 10, 2025
1 parent 9c490f8 commit cebdb5f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os/signal"
"path/filepath"
"strings"
"sync/atomic"
"syscall"
"testing"
"time"
Expand Down Expand Up @@ -495,13 +496,15 @@ 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() {
s, ok := <-sig
if !ok {
return
}
signalled.Store(true)
log.Warningf("%s: Got signal: %v", name, s)
done := make(chan bool, 1)
dArgs := append([]string{}, args...)
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit cebdb5f

Please sign in to comment.