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/e2e: improve command timeout handling #23551

Merged
merged 1 commit into from
Aug 8, 2024
Merged
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
13 changes: 10 additions & 3 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/exec"
"runtime"
"strings"
"syscall"
"time"

crypto_rand "crypto/rand"
Expand Down Expand Up @@ -368,9 +369,15 @@ func (s *PodmanSession) WaitWithDefaultTimeout() {
// WaitWithTimeout waits for process finished with DefaultWaitTimeout
func (s *PodmanSession) WaitWithTimeout(timeout int) {
Eventually(s, timeout).Should(Exit(), func() string {
// in case of timeouts show output
return fmt.Sprintf("command timed out after %ds: %v\nSTDOUT: %s\nSTDERR: %s",
timeout, s.Command.Args, string(s.Out.Contents()), string(s.Err.Contents()))
// Note eventually does not kill the command as such the command is leaked forever without killing it
// Also let's use SIGABRT to create a go stack trace so in case there is a deadlock we see it.
s.Signal(syscall.SIGABRT)
// Give some time to let the command print the output so it is not printed much later
// in the log at the wrong place.
time.Sleep(1 * time.Second)
// As the output is logged by default there no need to dump it here.
return fmt.Sprintf("command timed out after %ds: %v",
timeout, s.Command.Args)
})
os.Stdout.Sync()
os.Stderr.Sync()
Expand Down