add unit test

This commit is contained in:
lenhattan86 2021-10-06 16:15:51 -07:00
parent 9e166fae54
commit c985d9170f
2 changed files with 66 additions and 8 deletions

View file

@ -524,17 +524,19 @@ func (c *Client) RestartInstances(key aurora.JobKey, instances ...int32) error {
// Restarts specific instances specified with slaAware.
// If slaPolicy is nil, uses the existing slaPolicy of taskConfig.
func (c *Client) SlaRestartInstances(slaPolicy *aurora.SlaPolicy, jobKey *aurora.JobKey, instances ...int32) error {
func (c *Client) SlaRestartInstances(jobKey aurora.JobKey,
slaPolicy *aurora.SlaPolicy,
instances ...int32) (*aurora.StartJobUpdateResult_, error) {
c.logger.DebugPrintf("SlaRestartInstances Thrift Payload: %v %+v %v\n", slaPolicy, jobKey, instances)
if len(instances) == 0 {
c.logger.DebugPrintf("it is not necessary to restart 0 instances")
return nil
return nil, nil
}
jobSummary, err := c.GetJobSummary(jobKey.Role)
if err != nil {
return err
return nil, err
}
var jobConfig *aurora.JobConfiguration
for _, s := range jobSummary.Summaries {
@ -543,7 +545,7 @@ func (c *Client) SlaRestartInstances(slaPolicy *aurora.SlaPolicy, jobKey *aurora
}
}
if jobConfig == nil {
return fmt.Errorf("failed to find %v", jobKey)
return nil, fmt.Errorf("failed to find %v", jobKey)
}
// create job update request
@ -559,11 +561,11 @@ func (c *Client) SlaRestartInstances(slaPolicy *aurora.SlaPolicy, jobKey *aurora
}
msg := fmt.Sprintf("SlaRestartInstances %v-%v via StartJobUpdate", jobKey, instances)
if _, err := c.StartJobUpdate(jobUpdate, ""); err != nil {
return errors.Wrap(err, msg)
if result, err := c.StartJobUpdate(jobUpdate, fmt.Sprintf("restart instances %v", instances)); err != nil {
return nil, errors.Wrap(err, msg)
} else {
return result, nil
}
return nil
}
// Restarts all active tasks under a job configuration.