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

Interpret value of kill_delay as milliseconds #462

Merged
merged 2 commits into from
Dec 27, 2023
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
11 changes: 11 additions & 0 deletions runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,17 @@ func (c *Config) rerunDelay() time.Duration {
return time.Duration(c.Build.RerunDelay) * time.Millisecond
}

func (c *Config) killDelay() time.Duration {
// kill_delay can be specified as an integer or duration string
// interpret as milliseconds if less than the value of 1 millisecond
if c.Build.KillDelay < time.Millisecond {
return c.Build.KillDelay * time.Millisecond
} else {
// normalize kill delay to milliseconds
return time.Duration(c.Build.KillDelay.Milliseconds()) * time.Millisecond
}
}

func (c *Config) binPath() string {
return filepath.Join(c.Root, c.Build.Bin)
}
Expand Down
28 changes: 28 additions & 0 deletions runner/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"runtime"
"strings"
"testing"
"time"
)

const (
Expand Down Expand Up @@ -171,6 +172,33 @@ func TestReadConfigWithWrongPath(t *testing.T) {
}
}

func TestKillDelay(t *testing.T) {
config := Config{
Build: cfgBuild{
KillDelay: 1000,
},
}
if config.killDelay() != (1000 * time.Millisecond) {
t.Fatal("expect KillDelay 1000 to be interpreted as 1000 milliseconds, got ", config.killDelay())
}
config.Build.KillDelay = 1
if config.killDelay() != (1 * time.Millisecond) {
t.Fatal("expect KillDelay 1 to be interpreted as 1 millisecond, got ", config.killDelay())
}
config.Build.KillDelay = 1_000_000
if config.killDelay() != (1 * time.Millisecond) {
t.Fatal("expect KillDelay 1_000_000 to be interpreted as 1 millisecond, got ", config.killDelay())
}
config.Build.KillDelay = 100_000_000
if config.killDelay() != (100 * time.Millisecond) {
t.Fatal("expect KillDelay 100_000_000 to be interpreted as 100 milliseconds, got ", config.killDelay())
}
config.Build.KillDelay = 0
if config.killDelay() != 0 {
t.Fatal("expect KillDelay 0 to be interpreted as 0, got ", config.killDelay())
}
}

func contains(sl []string, target string) bool {
for _, c := range sl {
if c == target {
Expand Down
2 changes: 1 addition & 1 deletion runner/util_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) {
if err = syscall.Kill(-pid, syscall.SIGINT); err != nil {
return
}
time.Sleep(e.config.Build.KillDelay)
time.Sleep(e.config.killDelay())
}

// https://stackoverflow.com/questions/22470193/why-wont-go-kill-a-child-process-correctly
Expand Down
2 changes: 1 addition & 1 deletion runner/util_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) {
if err = syscall.Kill(-pid, syscall.SIGINT); err != nil {
return
}
time.Sleep(e.config.Build.KillDelay)
time.Sleep(e.config.killDelay())
}
// https://stackoverflow.com/questions/22470193/why-wont-go-kill-a-child-process-correctly
err = syscall.Kill(-pid, syscall.SIGKILL)
Expand Down
Loading