Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/runner: interrupt S/R loop if the test has been signalled #11418

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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