Skip to content

Commit

Permalink
internal/dag: fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yottahmd committed Aug 22, 2022
1 parent 34ee995 commit 918ab13
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
6 changes: 3 additions & 3 deletions internal/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,13 @@ func (b *builder) buildStep(variables []string, def *stepDef) (*Step, error) {
step.RepeatPolicy.Repeat = def.RepeatPolicy.Repeat
step.RepeatPolicy.Interval = time.Second * time.Duration(def.RepeatPolicy.IntervalSec)
}
if def.SignalOnStep != nil {
sigDef := *def.SignalOnStep
if def.SignalOnStop != nil {
sigDef := *def.SignalOnStop
sig := unix.SignalNum(sigDef)
if sig == 0 {
return nil, fmt.Errorf("invalid signal: %s", sigDef)
}
step.SignalOnStep = sigDef
step.SignalOnStop = sigDef
}
step.MailOnError = def.MailOnError
step.Preconditions = loadPreCondition(def.Preconditions)
Expand Down
2 changes: 1 addition & 1 deletion internal/dag/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type stepDef struct {
RepeatPolicy *repeatPolicyDef
MailOnError bool
Preconditions []*conditionDef
SignalOnStep *string
SignalOnStop *string
}

type continueOnDef struct {
Expand Down
36 changes: 36 additions & 0 deletions internal/dag/loader_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dag

import (
"fmt"
"path"
"testing"
"time"
Expand Down Expand Up @@ -81,6 +82,41 @@ steps:
require.Error(t, err)
}

func TestLoadSignalOnStop(t *testing.T) {
for _, tc := range []struct {
sig string
want string
err bool
}{
{
sig: "SIGINT",
want: "SIGINT",
err: false,
},
{
sig: "2000",
err: true,
},
} {
dat := fmt.Sprintf(`name: test DAG
steps:
- name: "1"
command: "true"
signalOnStop: "%s"
`, tc.sig)
l := &Loader{}
ret, err := l.LoadData([]byte(dat))
if tc.err {
require.Error(t, err)
continue
}
require.NoError(t, err)

step := ret.Steps[0]
require.Equal(t, step.SignalOnStop, tc.want)
}
}

func TestLoadErrorFileNotExist(t *testing.T) {
l := &Loader{}
_, err := l.Load(path.Join(testDir, "not_existing_file.yaml"), "")
Expand Down
2 changes: 1 addition & 1 deletion internal/dag/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Step struct {
RepeatPolicy RepeatPolicy
MailOnError bool
Preconditions []*Condition
SignalOnStep string
SignalOnStop string
}

type RetryPolicy struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/scheduler/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ func (n *Node) signal(sig os.Signal, allowOverride bool) {
status := n.Status
if status == NodeStatus_Running && n.cmd != nil {
sigsig := sig
if allowOverride && n.Step.SignalOnStep != "" {
sigsig = unix.SignalNum(n.Step.SignalOnStep)
if allowOverride && n.Step.SignalOnStop != "" {
sigsig = unix.SignalNum(n.Step.SignalOnStop)
}
log.Printf("Sending %s signal to %s", sigsig, n.Name)
utils.LogErr("sending signal", n.cmd.Kill(sigsig))
Expand Down
2 changes: 1 addition & 1 deletion internal/scheduler/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestSignalSpecified(t *testing.T) {
Command: "sleep",
Args: []string{"100"},
OutputVariables: &sync.Map{},
SignalOnStep: "SIGINT",
SignalOnStop: "SIGINT",
}}

go func() {
Expand Down

0 comments on commit 918ab13

Please sign in to comment.