disconnected clients: TaskGroup validation (#12418)

* TaskGroup: Validate that max_client_disconnect and stop_after_client_disconnect are mutually exclusive.
This commit is contained in:
Derek Strickland
2022-03-31 13:34:16 -04:00
committed by DerekStrickland
parent 8ac3e642e6
commit 6791147254
2 changed files with 7 additions and 2 deletions

View File

@@ -6294,6 +6294,10 @@ func (tg *TaskGroup) Validate(j *Job) error {
mErr.Errors = append(mErr.Errors, errors.New("Missing tasks for task group"))
}
if tg.MaxClientDisconnect != nil && tg.StopAfterClientDisconnect != nil {
mErr.Errors = append(mErr.Errors, errors.New("Task group cannot be configured with both max_client_disconnect and stop_after_client_disconnect"))
}
if tg.MaxClientDisconnect != nil && *tg.MaxClientDisconnect < 0 {
mErr.Errors = append(mErr.Errors, errors.New("max_client_disconnect cannot be negative"))
}

View File

@@ -415,7 +415,6 @@ func testJob() *Job {
"elb_check_interval": "30s",
"elb_check_min": "3",
},
MaxClientDisconnect: helper.TimeToPtr(1 * time.Hour),
},
},
Meta: map[string]string{
@@ -5880,7 +5879,6 @@ func TestParameterizedJobConfig_Validate_NonBatch(t *testing.T) {
func TestJobConfig_Validate_StopAferClientDisconnect(t *testing.T) {
ci.Parallel(t)
// Setup a system Job with stop_after_client_disconnect set, which is invalid
job := testJob()
job.Type = JobTypeSystem
@@ -5912,14 +5910,17 @@ func TestJobConfig_Validate_MaxClientDisconnect(t *testing.T) {
job := testJob()
timeout := -1 * time.Minute
job.TaskGroups[0].MaxClientDisconnect = &timeout
job.TaskGroups[0].StopAfterClientDisconnect = &timeout
err := job.Validate()
require.Error(t, err)
require.Contains(t, err.Error(), "max_client_disconnect cannot be negative")
require.Contains(t, err.Error(), "Task group cannot be configured with both max_client_disconnect and stop_after_client_disconnect")
// Modify the job with a valid max_client_disconnect value
timeout = 1 * time.Minute
job.TaskGroups[0].MaxClientDisconnect = &timeout
job.TaskGroups[0].StopAfterClientDisconnect = nil
err = job.Validate()
require.NoError(t, err)
}