Skip to content

Commit

Permalink
adding process.Kill() to tests
Browse files Browse the repository at this point in the history
Signed-off-by: CodeChanning <chxgaddy@amazon.com>
  • Loading branch information
CodeChanning committed Jun 21, 2024
1 parent d93df3f commit 23dedaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions cmd/nerdctl/container_run_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,21 @@ func runSigProxy(t *testing.T, args ...string) (string, bool, bool) {
testutil.SigProxyTestScript,
)

process := base.Cmd(fullArgs...).Start()
result := base.Cmd(fullArgs...).Start()
process := result.Cmd.Process

// This sleep waits for until we reach the trap command in the shell script, if sigint is send before that we dont enter the while loop.
// Waits until we reach the trap command in the shell script, then sends SIGINT.
time.Sleep(3 * time.Second)
syscall.Kill(process.Cmd.Process.Pid, syscall.SIGINT)
syscall.Kill(process.Pid, syscall.SIGINT)

//define wait delay to avoid timeout
process.Cmd.WaitDelay = 3 * time.Second
process.Cmd.Wait()
// Waits until SIGINT is sent and responded to, then kills process to avoid timeout
time.Sleep(3 * time.Second)
process.Kill()

sigIntRecieved := strings.Contains(result.Stdout(), testutil.SigProxyTrueOut)
timedOut := strings.Contains(result.Stdout(), testutil.SigProxyTimeoutMsg)

return process.Stdout(), strings.Contains(process.Stdout(), testutil.SigProxyTrueOut), strings.Contains(process.Stdout(), testutil.SigProxyTimeoutMsg)
return result.Stdout(), sigIntRecieved, timedOut
}

func TestRunSigProxy(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/testutil/testutil_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var (
ExpectedConnectionRefusedError = "connection refused"

SigProxyTrueOut = "received SIGINT"
SigProxyTimeoutMsg = "Timed Out; No SIGINT received"
SigProxyTimeoutMsg = "Timed Out; No signal received"
SigProxyTestScript = `#!/bin/sh
set -eu
Expand Down

0 comments on commit 23dedaa

Please sign in to comment.