Skip to content

Commit

Permalink
Set health timeout to health interval if omitted.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias Brange authored and Justin Reagor committed Apr 2, 2018
1 parent 92f9b8f commit c9a734a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jobs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (cfg *Config) validateHealthCheck() error {
}
checkTimeout = parsedTimeout
} else {
checkTimeout = cfg.execTimeout
checkTimeout = cfg.heartbeatInterval
}

if cfg.Health.CheckExec != nil {
Expand Down
15 changes: 15 additions & 0 deletions jobs/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ func TestJobConfigServiceWithPreStart(t *testing.T) {
assert.Nil(job1.serviceDefinition, "config for job1.serviceDefinition")
}

func TestJobConfigHealthTimeout(t *testing.T) {
jobs := loadTestConfig(t)
assert := assert.New(t)

job0 := jobs[0]
assert.Equal(job0.Name, "serviceA", "config for job0.Name")
assert.Equal(job0.heartbeatInterval, time.Duration(10) * time.Second, "config for job0.Health")
assert.Equal(job0.healthCheckExec.Timeout, time.Duration(5) * time.Second, "config for job0.Name.Health")

job1 := jobs[1]
assert.Equal(job1.Name, "serviceB", "config for job1.Name")
assert.Equal(job1.heartbeatInterval, time.Duration(10) * time.Second, "config for job1.Health")
assert.Equal(job1.healthCheckExec.Timeout, job1.heartbeatInterval, "config for job1.Health")
}

func TestJobConfigServiceWithArrayExec(t *testing.T) {
jobs := loadTestConfig(t)
assert := assert.New(t)
Expand Down
23 changes: 23 additions & 0 deletions jobs/testdata/TestJobConfigHealthTimeout.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
name: "serviceA",
port: 80,
exec: "/bin/serviceA",
health: {
exec: "/bin/healthCheckA.sh",
interval: 10,
ttl: 20,
timeout: "5s"
}
},
{
name: "serviceB",
port: 80,
exec: "/bin/serviceB",
health: {
exec: "/bin/healthCheckB.sh",
interval: 10,
ttl: 20,
}
}
]

0 comments on commit c9a734a

Please sign in to comment.