ensure shutdown delay can be removed

This commit is contained in:
Drew Bailey 2020-04-06 11:33:04 -04:00
parent 9874e7b21d
commit 0d550049e9
No known key found for this signature in database
GPG key ID: FBA61B9FB7CCE1A7
2 changed files with 15 additions and 7 deletions

View file

@ -111,19 +111,18 @@ func (h *groupServiceHook) Update(req *interfaces.RunnerUpdateRequest) error {
networks = req.Alloc.AllocatedResources.Shared.Networks networks = req.Alloc.AllocatedResources.Shared.Networks
} }
// Update group service hook fields
tg := req.Alloc.Job.LookupTaskGroup(h.group) tg := req.Alloc.Job.LookupTaskGroup(h.group)
h.networks = networks
h.services = tg.Services
h.canary = canary
h.taskEnvBuilder.UpdateTask(req.Alloc, nil)
// Update shutdown delay
var shutdown time.Duration var shutdown time.Duration
if tg.ShutdownDelay != nil { if tg.ShutdownDelay != nil {
shutdown = *tg.ShutdownDelay shutdown = *tg.ShutdownDelay
} }
// Update group service hook fields
h.networks = networks
h.services = tg.Services
h.canary = canary
h.delay = shutdown h.delay = shutdown
h.taskEnvBuilder.UpdateTask(req.Alloc, nil)
// Create new task services struct with those new values // Create new task services struct with those new values
newWorkloadServices := h.getWorkloadServices() newWorkloadServices := h.getWorkloadServices()

View file

@ -77,12 +77,21 @@ func TestGroupServiceHook_ShutdownDelayUpdate(t *testing.T) {
}) })
require.NoError(t, h.Prerun()) require.NoError(t, h.Prerun())
// Incease shutdown Delay
alloc.Job.TaskGroups[0].ShutdownDelay = helper.TimeToPtr(15 * time.Second) alloc.Job.TaskGroups[0].ShutdownDelay = helper.TimeToPtr(15 * time.Second)
req := &interfaces.RunnerUpdateRequest{Alloc: alloc} req := &interfaces.RunnerUpdateRequest{Alloc: alloc}
require.NoError(t, h.Update(req)) require.NoError(t, h.Update(req))
// Assert that update updated the delay value // Assert that update updated the delay value
require.Equal(t, h.delay, 15*time.Second) require.Equal(t, h.delay, 15*time.Second)
// Remove shutdown delay
alloc.Job.TaskGroups[0].ShutdownDelay = nil
req = &interfaces.RunnerUpdateRequest{Alloc: alloc}
require.NoError(t, h.Update(req))
// Assert that update updated the delay value
require.Equal(t, h.delay, 0*time.Second)
} }
// TestGroupServiceHook_GroupServices asserts group service hooks with group // TestGroupServiceHook_GroupServices asserts group service hooks with group