mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
consul: fix task deregistration hook
Broke ShutdownDelay but the test was timing dependent so it just appeared flaky. Made the test slower so that it should never incorrectly pass.
This commit is contained in:
@@ -140,7 +140,7 @@ func (h *serviceHook) Update(ctx context.Context, req *interfaces.TaskUpdateRequ
|
||||
return h.consul.UpdateTask(oldTaskServices, newTaskServices)
|
||||
}
|
||||
|
||||
func (h *serviceHook) Killing(ctx context.Context, req *interfaces.TaskPreKillRequest, resp *interfaces.TaskPreKillResponse) error {
|
||||
func (h *serviceHook) PreKilling(ctx context.Context, req *interfaces.TaskPreKillRequest, resp *interfaces.TaskPreKillResponse) error {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
|
||||
|
||||
@@ -3,11 +3,18 @@ package taskrunner
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
|
||||
"github.com/hashicorp/nomad/client/taskenv"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// Statically assert the stats hook implements the expected interfaces
|
||||
var _ interfaces.TaskPoststartHook = (*serviceHook)(nil)
|
||||
var _ interfaces.TaskExitedHook = (*serviceHook)(nil)
|
||||
var _ interfaces.TaskPreKillHook = (*serviceHook)(nil)
|
||||
var _ interfaces.TaskUpdateHook = (*serviceHook)(nil)
|
||||
|
||||
// TestTaskRunner_ServiceHook_InterpolateServices asserts that all service
|
||||
// and check fields are properly interpolated.
|
||||
func TestTaskRunner_ServiceHook_InterpolateServices(t *testing.T) {
|
||||
|
||||
@@ -462,7 +462,7 @@ func (tr *TaskRunner) preKill() {
|
||||
var start time.Time
|
||||
if tr.logger.IsTrace() {
|
||||
start = time.Now()
|
||||
tr.logger.Trace("running kill hook", "name", name, "start", start)
|
||||
tr.logger.Trace("running prekill hook", "name", name, "start", start)
|
||||
}
|
||||
|
||||
// Run the pre kill hook
|
||||
@@ -470,14 +470,14 @@ func (tr *TaskRunner) preKill() {
|
||||
var resp interfaces.TaskPreKillResponse
|
||||
if err := killHook.PreKilling(context.Background(), &req, &resp); err != nil {
|
||||
tr.emitHookError(err, name)
|
||||
tr.logger.Error("kill hook failed", "name", name, "error", err)
|
||||
tr.logger.Error("prekill hook failed", "name", name, "error", err)
|
||||
}
|
||||
|
||||
// No need to persist as TaskKillResponse is currently empty
|
||||
|
||||
if tr.logger.IsTrace() {
|
||||
end := time.Now()
|
||||
tr.logger.Trace("finished kill hook", "name", name, "end", end, "duration", end.Sub(start))
|
||||
tr.logger.Trace("finished prekill hook", "name", name, "end", end, "duration", end.Sub(start))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,7 +468,7 @@ func TestTaskRunner_ShutdownDelay(t *testing.T) {
|
||||
}
|
||||
|
||||
// No shutdown escape hatch for this delay, so don't set it too high
|
||||
task.ShutdownDelay = 500 * time.Duration(testutil.TestMultiplier()) * time.Millisecond
|
||||
task.ShutdownDelay = 1000 * time.Duration(testutil.TestMultiplier()) * time.Millisecond
|
||||
|
||||
conf, cleanup := testTaskRunnerConfig(t, alloc, task.Name)
|
||||
defer cleanup()
|
||||
|
||||
Reference in New Issue
Block a user