Code review feedback

This commit is contained in:
Preetha Appan 2018-01-29 16:31:25 -06:00
parent a1237d627a
commit 9d15e0c05b
No known key found for this signature in database
GPG Key ID: 9F7C19990A50EAFC
3 changed files with 36 additions and 12 deletions

View File

@ -171,14 +171,15 @@ func (a Allocation) RescheduleInfo(t time.Time) (int, int) {
reschedulePolicy = tg.ReschedulePolicy
}
}
var availableAttempts int
var interval time.Duration
if reschedulePolicy != nil {
availableAttempts = *reschedulePolicy.Attempts
interval = *reschedulePolicy.Interval
if reschedulePolicy == nil {
return 0, 0
}
availableAttempts := *reschedulePolicy.Attempts
interval := *reschedulePolicy.Interval
attempted := 0
// Loop over reschedule tracker to find attempts within the restart policy's interval
if a.RescheduleTracker != nil && availableAttempts > 0 && interval > 0 {
attempted := 0
for j := len(a.RescheduleTracker.Events) - 1; j >= 0; j-- {
lastAttempt := a.RescheduleTracker.Events[j].RescheduleTime
timeDiff := t.UTC().UnixNano() - lastAttempt
@ -186,9 +187,8 @@ func (a Allocation) RescheduleInfo(t time.Time) (int, int) {
attempted += 1
}
}
return attempted, availableAttempts
}
return 0, availableAttempts
return attempted, availableAttempts
}
// RescheduleTracker encapsulates previous reschedule events

View File

@ -281,7 +281,7 @@ func formatAllocBasicInfo(alloc *api.Allocation, client *api.Client, uuidLength
}
if alloc.NextAllocation != "" {
basic = append(basic,
fmt.Sprintf("Rescheduled Alloc ID|%s", limit(alloc.NextAllocation, uuidLength)))
fmt.Sprintf("Replacement Alloc ID|%s", limit(alloc.NextAllocation, uuidLength)))
}
if verbose {

View File

@ -173,6 +173,31 @@ func TestAllocStatusCommand_Run(t *testing.T) {
}
ui.OutputWriter.Reset()
}
func TestAllocStatusCommand_RescheduleInfo(t *testing.T) {
t.Parallel()
srv, client, url := testServer(t, true, nil)
defer srv.Shutdown()
// Wait for a node to be ready
testutil.WaitForResult(func() (bool, error) {
nodes, _, err := client.Nodes().List(nil)
if err != nil {
return false, err
}
for _, node := range nodes {
if node.Status == structs.NodeStatusReady {
return true, nil
}
}
return false, fmt.Errorf("no ready nodes")
}, func(err error) {
t.Fatalf("err: %v", err)
})
ui := new(cli.MockUi)
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}
// Test reschedule attempt info
require := require.New(t)
state := srv.Agent.Server().State()
@ -194,10 +219,9 @@ func TestAllocStatusCommand_Run(t *testing.T) {
if code := cmd.Run([]string{"-address=" + url, a.ID}); code != 0 {
t.Fatalf("expected exit 0, got: %d", code)
}
out = ui.OutputWriter.String()
require.Contains(out, "Rescheduled Alloc ID")
out := ui.OutputWriter.String()
require.Contains(out, "Replacement Alloc ID")
require.Regexp(regexp.MustCompile(".*Reschedule Attempts\\s*=\\s*1/2"), out)
}
func TestAllocStatusCommand_AutocompleteArgs(t *testing.T) {