Skip to content

Commit

Permalink
Experiments passed duration succeed with running analysis (argoproj#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
dthomson25 authored Feb 6, 2020
1 parent a2bf90d commit beeeb56
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 7 deletions.
48 changes: 44 additions & 4 deletions experiments/analysisrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,14 @@ func TestAssessAnalysisRunStatusesAfterTemplateSuccess(t *testing.T) {
e := newExperiment("foo", templates, "")
e.Spec.Analyses = []v1alpha1.ExperimentAnalysisTemplateRef{
{
Name: "success-rate",
TemplateName: "success-rate",
Name: "success-rate",
TemplateName: "success-rate",
RequiredForCompletion: true,
},
{
Name: "latency",
TemplateName: "latency",
Name: "latency",
TemplateName: "latency",
RequiredForCompletion: true,
},
}
e.Status.Phase = v1alpha1.AnalysisPhaseRunning
Expand Down Expand Up @@ -569,6 +571,44 @@ func TestDoNotCompleteExperimentWithRemainingRequiredAnalysisRun(t *testing.T) {
assert.NotEqual(t, patchedEx.Status.Phase, v1alpha1.AnalysisPhaseSuccessful)
}

func TestCompleteExperimentWithNoRequiredAnalysis(t *testing.T) {
templates := generateTemplates("bar")
e := newExperiment("foo", templates, "1m")
e.Spec.Analyses = []v1alpha1.ExperimentAnalysisTemplateRef{
{
Name: "success-rate",
TemplateName: "success-rate",
},
}
e.Status.Phase = v1alpha1.AnalysisPhaseRunning
e.Status.AvailableAt = secondsAgo(61)
rs := templateToRS(e, templates[0], 0)
rs.Spec.Replicas = new(int32)
ar := analysisTemplateToRun("success-rate", e, &v1alpha1.AnalysisTemplateSpec{})
ar.Status = v1alpha1.AnalysisRunStatus{
Phase: v1alpha1.AnalysisPhaseRunning,
}
e.Status.TemplateStatuses = []v1alpha1.TemplateStatus{{
Name: "bar",
Status: v1alpha1.TemplateStatusSuccessful,
}}
e.Status.AnalysisRuns = []v1alpha1.ExperimentAnalysisRunStatus{
{
Name: e.Spec.Analyses[0].Name,
Phase: v1alpha1.AnalysisPhaseRunning,
AnalysisRun: ar.Name,
},
}

f := newFixture(t, e, rs, ar)
defer f.Close()
patchIndex := f.expectPatchExperimentAction(e)
f.run(getKey(e, t))
patchedEx := f.getPatchedExperimentAsObj(patchIndex)
//assert.True(t, patchedEx.Spec.Terminate)
assert.Equal(t, patchedEx.Status.Phase, v1alpha1.AnalysisPhaseSuccessful)
}

// TestTerminateAnalysisRuns verifies we terminate analysis runs when experiment is terminating
func TestTerminateAnalysisRuns(t *testing.T) {
templates := generateTemplates("bar")
Expand Down
7 changes: 4 additions & 3 deletions experiments/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,11 @@ func (ec *experimentContext) calculateStatus() *v1alpha1.ExperimentStatus {
ec.log.Infof("Marked AvailableAt: %v", now)
}
if templateStatus.Completed() {
if templateStatus == v1alpha1.AnalysisPhaseSuccessful {
analysisRun := analysesStatus.Completed() || experimentutil.HasRequiredAnalysisRuns(ec.ex)
if templateStatus == v1alpha1.AnalysisPhaseSuccessful && analysisRun {
// If the templates have completed successfully (e.g. it ran without degrading for
// the entire duration), then the status of the Experiment is deferred to the status
// the analyses results.
// the entire duration), and there are required analysis runs or they have completed, then
// the status of the Experiment is deferred to the status of the analyses results.
ec.newStatus.Phase = analysesStatus
ec.newStatus.Message = analysesMessage
} else {
Expand Down
9 changes: 9 additions & 0 deletions utils/experiment/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ func IsTerminating(experiment *v1alpha1.Experiment) bool {
return RequiredAnalysisRunsSuccessful(experiment, &experiment.Status)
}

func HasRequiredAnalysisRuns(ex *v1alpha1.Experiment) bool {
for _, analysis := range ex.Spec.Analyses {
if analysis.RequiredForCompletion {
return true
}
}
return false
}

// RequiredAnalysisRunsSuccessful has at least one required for completition analysis run
// and it completed successfully
func RequiredAnalysisRunsSuccessful(ex *v1alpha1.Experiment, exStatus *v1alpha1.ExperimentStatus) bool {
Expand Down
15 changes: 15 additions & 0 deletions utils/experiment/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,18 @@ func TestRequiredAnalysisRunsSuccessful(t *testing.T) {
e.Status.AnalysisRuns[0].Phase = v1alpha1.AnalysisPhaseSuccessful
assert.True(t, RequiredAnalysisRunsSuccessful(e, &e.Status))
}

func TestHasRequiredAnalysisRuns(t *testing.T) {
e := &v1alpha1.Experiment{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
},
}
assert.False(t, HasRequiredAnalysisRuns(e))
e.Spec.Analyses = []v1alpha1.ExperimentAnalysisTemplateRef{{
Name: "foo",
}}
assert.False(t, HasRequiredAnalysisRuns(e))
e.Spec.Analyses[0].RequiredForCompletion = true
assert.True(t, HasRequiredAnalysisRuns(e))
}

0 comments on commit beeeb56

Please sign in to comment.