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

fix: TestShell timeouts #128

Merged
merged 2 commits into from
Dec 5, 2024
Merged
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
8 changes: 4 additions & 4 deletions exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func TestCommandRun(t *testing.T) {
"Error when the registry is inaccessible": {cmd: "exit 0", registryInaccessible: true, wantError: true},

// Timeout context test cases
"Success without timing out": {cmd: "exit 0", timeout: 10 * time.Second},
"Error when the command's exit code is non-zero without timing out": {cmd: "exit 42", timeout: 10 * time.Second, wantError: true, wantExitCode: 42},
"Success without timing out": {cmd: "exit 0", timeout: 1 * time.Minute},
"Error when the command's exit code is non-zero without timing out": {cmd: "exit 42", timeout: 1 * time.Minute, wantError: true, wantExitCode: 42},
"Error with a non-registered distro without timing out": {cmd: "exit 0", fakeDistro: true, wantError: true},
"Error when timing out before Run": {cmd: "exit 0", timeout: 1 * time.Nanosecond, wantError: true},
"Error when timing out during Run": {cmd: "sleep 5", timeout: 2 * time.Second, wantError: true},
Expand Down Expand Up @@ -222,8 +222,8 @@ func TestCommandStartWait(t *testing.T) {
"Error when the command returns non-zero and piping both stdout and stderr": {distro: &realDistro, cmd: "echo 'Hello!' && sleep 1 && echo 'Error!' >&2 && exit 42", stdoutPipe: true, wantStdout: "Hello!\n", stderrPipe: true, wantStderr: "Error!\n", wantErrOn: AfterWait, wantExitError: 42},

// Timeout context
"Success when not timing out": {distro: &realDistro, cmd: "exit 0", timeout: 10 * time.Second},
"Error when command returns non-zero without timing out": {distro: &realDistro, cmd: "exit 42", timeout: 10 * time.Second, wantErrOn: AfterWait, wantExitError: 42},
"Success when not timing out": {distro: &realDistro, cmd: "exit 0", timeout: 1 * time.Minute},
"Error when command returns non-zero without timing out": {distro: &realDistro, cmd: "exit 42", timeout: 1 * time.Minute, wantErrOn: AfterWait, wantExitError: 42},
"Error when timing out before execution": {distro: &realDistro, cmd: "exit 0", timeout: time.Nanosecond, wantErrOn: AfterStart},
"Error when timing out during execution": {distro: &realDistro, cmd: "sleep 5", timeout: 3 * time.Second, wantErrOn: AfterWait},

Expand Down
2 changes: 1 addition & 1 deletion shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestShell(t *testing.T) {

// Because Shell is an interactive command, it needs to be quit from
// outside. This goroutine sets a fuse before shutting down the distro.
tk := time.AfterFunc(10*time.Second, func() {
tk := time.AfterFunc(1*time.Minute, func() {
CarlosNihelton marked this conversation as resolved.
Show resolved Hide resolved
t.Logf("Command timed out")
err := d.Terminate()
if err != nil {
Expand Down
Loading