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

Timeout for acceptance tests #2168

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
29 changes: 28 additions & 1 deletion acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"slices"
"sort"
"strings"
"syscall"
"testing"
"time"

Expand All @@ -22,7 +23,10 @@
"github.com/stretchr/testify/require"
)

var KeepTmp = os.Getenv("KEEP_TMP") != ""
var (
KeepTmp = os.Getenv("KEEP_TMP") != ""
defaultTimeout = 10 * time.Second
)

const (
EntryPointScript = "script"
Expand Down Expand Up @@ -155,7 +159,13 @@
cmd.Env = append(os.Environ(), "GOCOVERDIR="+coverDir)
}
cmd.Dir = tmpDir
if runtime.GOOS != "windows" {
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}

Check failure on line 163 in acceptance/acceptance_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

unknown field Setpgid in struct literal of type "syscall".SysProcAttr

Check failure on line 163 in acceptance/acceptance_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

unknown field Setpgid in struct literal of type "syscall".SysProcAttr
}

timer := KillTimer(cmd, defaultTimeout)
outB, err := cmd.CombinedOutput()
timer.Stop()

out := formatOutput(string(outB), err)
out = repls.Replace(out)
Expand Down Expand Up @@ -373,3 +383,20 @@
return copyFile(path, destPath)
})
}

func KillTimer(cmd *exec.Cmd, timeout time.Duration) *time.Timer {
return time.AfterFunc(timeout, func() {
if cmd.Process == nil {
return
}
if runtime.GOOS == "windows" {
// best effort, not killing the group like on mac/linux
_ = cmd.Process.Kill()
} else {
pgid, err := syscall.Getpgid(cmd.Process.Pid)

Check failure on line 396 in acceptance/acceptance_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: syscall.Getpgid

Check failure on line 396 in acceptance/acceptance_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: syscall.Getpgid
if err == nil {
_ = syscall.Kill(-pgid, syscall.SIGKILL)

Check failure on line 398 in acceptance/acceptance_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: syscall.Kill

Check failure on line 398 in acceptance/acceptance_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: syscall.Kill
}
}
})
}
1 change: 1 addition & 0 deletions acceptance/bundle/variables/empty/script
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sleep 12
$CLI bundle validate
Loading