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
}
// Update group service hook fields
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
if tg.ShutdownDelay != nil {
shutdown = *tg.ShutdownDelay
}
// Update group service hook fields
h.networks = networks
h.services = tg.Services
h.canary = canary
h.delay = shutdown
h.taskEnvBuilder.UpdateTask(req.Alloc, nil)
// Create new task services struct with those new values
newWorkloadServices := h.getWorkloadServices()

View File

@ -77,12 +77,21 @@ func TestGroupServiceHook_ShutdownDelayUpdate(t *testing.T) {
})
require.NoError(t, h.Prerun())
// Incease shutdown Delay
alloc.Job.TaskGroups[0].ShutdownDelay = helper.TimeToPtr(15 * time.Second)
req := &interfaces.RunnerUpdateRequest{Alloc: alloc}
require.NoError(t, h.Update(req))
// Assert that update updated the delay value
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