From ec03c7e094addebf1e850b3fccbf12edeafb9235 Mon Sep 17 00:00:00 2001 From: Yurii Popivniak Date: Fri, 4 Oct 2024 21:21:03 +0300 Subject: [PATCH] test: add test for background analysis with inconclusive result Signed-off-by: Yurii Popivniak --- test/e2e/analysis_test.go | 23 ++++++++++++++ ...stemplate-web-background-inconclusive.yaml | 19 ++++++++++++ ...lout-background-analysis-inconclusive.yaml | 30 +++++++++++++++++++ test/fixtures/then.go | 12 ++++++++ test/fixtures/when.go | 8 +++++ 5 files changed, 92 insertions(+) create mode 100644 test/e2e/functional/analysistemplate-web-background-inconclusive.yaml create mode 100644 test/e2e/functional/rollout-background-analysis-inconclusive.yaml diff --git a/test/e2e/analysis_test.go b/test/e2e/analysis_test.go index 13b6d19b60..56fb82815d 100644 --- a/test/e2e/analysis_test.go +++ b/test/e2e/analysis_test.go @@ -27,6 +27,7 @@ func (s *AnalysisSuite) SetupSuite() { s.E2ESuite.SetupSuite() // shared analysis templates for suite s.ApplyManifests("@functional/analysistemplate-web-background.yaml") + s.ApplyManifests("@functional/analysistemplate-web-background-inconclusive.yaml") s.ApplyManifests("@functional/analysistemplate-sleep-job.yaml") s.ApplyManifests("@functional/analysistemplate-multiple-job.yaml") s.ApplyManifests("@functional/analysistemplate-fail-multiple-job.yaml") @@ -68,6 +69,28 @@ func (s *AnalysisSuite) TestCanaryBackgroundAnalysis() { WaitForBackgroundAnalysisRunPhase("Successful") } +func (s *AnalysisSuite) TestCanaryInconclusiveBackgroundAnalysis() { + s.Given(). + RolloutObjects("@functional/rollout-background-analysis-inconclusive.yaml"). + When(). + ApplyManifests(). + WaitForRolloutStatus("Healthy"). + Then(). + ExpectAnalysisRunCount(0). + When(). + UpdateSpec(). + WaitForRolloutStatus("Paused"). + Then(). + ExpectAnalysisRunCount(1). + ExpectBackgroundAnalysisRunPhase("Running"). + When(). + WaitForBackgroundAnalysisRunPhase("Inconclusive"). + WaitForRolloutMessage("InconclusiveAnalysisRun"). + Then(). + ExpectRolloutStatus("Paused"). + ExpectRolloutMessage("InconclusiveAnalysisRun") +} + func (s *AnalysisSuite) TestCanaryInlineAnalysis() { s.Given(). RolloutObjects("@functional/rollout-inline-analysis.yaml"). diff --git a/test/e2e/functional/analysistemplate-web-background-inconclusive.yaml b/test/e2e/functional/analysistemplate-web-background-inconclusive.yaml new file mode 100644 index 0000000000..ee9ec64b68 --- /dev/null +++ b/test/e2e/functional/analysistemplate-web-background-inconclusive.yaml @@ -0,0 +1,19 @@ +# A dummy web metric which uses the kubernetes version endpoint as a metric provider +apiVersion: argoproj.io/v1alpha1 +kind: AnalysisTemplate +metadata: + name: web-background-inconclusive +spec: + args: + - name: url-val + value: "https://kubernetes.default.svc/version" + metrics: + - name: web + interval: 7s + inconclusiveLimit: 3 + successCondition: result.major == '2000' + failureCondition: result.major == '1000' + provider: + web: + url: "{{args.url-val}}" + insecure: true diff --git a/test/e2e/functional/rollout-background-analysis-inconclusive.yaml b/test/e2e/functional/rollout-background-analysis-inconclusive.yaml new file mode 100644 index 0000000000..932655fb46 --- /dev/null +++ b/test/e2e/functional/rollout-background-analysis-inconclusive.yaml @@ -0,0 +1,30 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +metadata: + name: rollout-background-analysis-inconclusive +spec: + replicas: 2 + strategy: + canary: + steps: + - setWeight: 10 + - pause: { duration: 30s } + analysis: + templates: + - templateName: web-background-inconclusive + startingStep: 1 + selector: + matchLabels: + app: rollout-background-analysis-inconclusive + template: + metadata: + labels: + app: rollout-background-analysis-inconclusive + spec: + containers: + - name: rollouts-demo + image: nginx:1.19-alpine + resources: + requests: + memory: 16Mi + cpu: 5m diff --git a/test/fixtures/then.go b/test/fixtures/then.go index d39e054d34..2a63465dbc 100644 --- a/test/fixtures/then.go +++ b/test/fixtures/then.go @@ -55,6 +55,18 @@ func (t *Then) ExpectRolloutStatus(expectedStatus string) *Then { return t } +func (t *Then) ExpectRolloutMessage(expectedMessage string) *Then { + ro, err := t.rolloutClient.ArgoprojV1alpha1().Rollouts(t.namespace).Get(t.Context, t.rollout.GetName(), metav1.GetOptions{}) + t.CheckError(err) + _, message := rolloututil.GetRolloutPhase(ro) + if message != expectedMessage { + t.log.Errorf("Rollout message expected to be '%s'. actual: %s", expectedMessage, message) + t.t.FailNow() + } + t.log.Infof("Rollout expectation status=%s met", expectedMessage) + return t +} + func (t *Then) ExpectReplicaCounts(desired, current, updated, ready, available any) *Then { ro, err := t.rolloutClient.ArgoprojV1alpha1().Rollouts(t.namespace).Get(t.Context, t.rollout.GetName(), metav1.GetOptions{}) t.CheckError(err) diff --git a/test/fixtures/when.go b/test/fixtures/when.go index a5806befb9..10b4b5b7fe 100644 --- a/test/fixtures/when.go +++ b/test/fixtures/when.go @@ -278,6 +278,14 @@ func (w *When) WaitForRolloutStatus(status string, timeout ...time.Duration) *Wh return w.WaitForRolloutCondition(checkStatus, fmt.Sprintf("status=%s", status), timeout...) } +func (w *When) WaitForRolloutMessage(message string, timeout ...time.Duration) *When { + checkStatus := func(ro *rov1.Rollout) bool { + _, m := rolloututil.GetRolloutPhase(ro) + return m == message + } + return w.WaitForRolloutCondition(checkStatus, fmt.Sprintf("message=%s", message), timeout...) +} + func (w *When) MarkPodsReady(revision string, count int, timeouts ...time.Duration) *When { ticker := time.NewTicker(time.Second) defer ticker.Stop()