Skip to content

Commit 23dedaa

Browse files
committed
adding process.Kill() to tests
Signed-off-by: CodeChanning <[email protected]>
1 parent d93df3f commit 23dedaa

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

cmd/nerdctl/container_run_linux_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,21 @@ func runSigProxy(t *testing.T, args ...string) (string, bool, bool) {
329329
testutil.SigProxyTestScript,
330330
)
331331

332-
process := base.Cmd(fullArgs...).Start()
332+
result := base.Cmd(fullArgs...).Start()
333+
process := result.Cmd.Process
333334

334-
// 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.
335+
// Waits until we reach the trap command in the shell script, then sends SIGINT.
335336
time.Sleep(3 * time.Second)
336-
syscall.Kill(process.Cmd.Process.Pid, syscall.SIGINT)
337+
syscall.Kill(process.Pid, syscall.SIGINT)
337338

338-
//define wait delay to avoid timeout
339-
process.Cmd.WaitDelay = 3 * time.Second
340-
process.Cmd.Wait()
339+
// Waits until SIGINT is sent and responded to, then kills process to avoid timeout
340+
time.Sleep(3 * time.Second)
341+
process.Kill()
342+
343+
sigIntRecieved := strings.Contains(result.Stdout(), testutil.SigProxyTrueOut)
344+
timedOut := strings.Contains(result.Stdout(), testutil.SigProxyTimeoutMsg)
341345

342-
return process.Stdout(), strings.Contains(process.Stdout(), testutil.SigProxyTrueOut), strings.Contains(process.Stdout(), testutil.SigProxyTimeoutMsg)
346+
return result.Stdout(), sigIntRecieved, timedOut
343347
}
344348

345349
func TestRunSigProxy(t *testing.T) {

pkg/testutil/testutil_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var (
5858
ExpectedConnectionRefusedError = "connection refused"
5959

6060
SigProxyTrueOut = "received SIGINT"
61-
SigProxyTimeoutMsg = "Timed Out; No SIGINT received"
61+
SigProxyTimeoutMsg = "Timed Out; No signal received"
6262
SigProxyTestScript = `#!/bin/sh
6363
set -eu
6464

0 commit comments

Comments
 (0)