Skip to content

Suite for running upgrade tests in Knative components#1652

Merged
knative-prow-robot merged 27 commits into
knative:masterfrom
cardil:feature/upgrade-test-framework
Sep 18, 2020
Merged

Suite for running upgrade tests in Knative components#1652
knative-prow-robot merged 27 commits into
knative:masterfrom
cardil:feature/upgrade-test-framework

Conversation

@cardil
Copy link
Copy Markdown
Contributor

@cardil cardil commented Aug 27, 2020

Fixes #1638

This introduces a pluggable test suite for running upgrade tests in Knative components. Test suite is fully configurable, so that can be used for upgrade testing in Knative Serving, and Eventing, and Operator. Different configuration can be used by vendors that needs this to be slightly different.

This change will dramatically reduce the needed Bash code there is and let us run Serving and Eventing upgrade tests in the same time.

The idea in this PR is to define reusable plugins in Knative components (Serving, Eventing), use them in test code, and reuse them in integration (Operator) and vendor projects (like OpenShift Serverless). Creation of plugins can be done by implementing Operation or BackgroundOperation interfaces, or by using convenience methods of NewOperation, NewBackgroundOperation (with WaitForStopEvent), or NewBackgroundVerification.

Below are examples of such plugin wrote for Serving continual tests (that will be running in background) and a complete upgrade test:

// file: knative.dev/serving/test/e2e/upgrade/continual.go
package upgrade

import (
  pkgupgrade "knative.dev/pkg/test/upgrade"
  "knative.dev/serving/test/e2e"
)

func ContinualTest() pkgupgrade.BackgroundOperation {
  var (
    namespace string
    service   string
  )
  return upgrade.NewBackgroundVerification("Serving continual test",
    func(c upgrade.Context) {
      namespace = e2e.GenerateTestName("serving-upgrades")
      service = e2e.GenerateTestName("prober")
      e2e.Clients.Knative.Serving.Namespace(namespace).Create(Service{
         // [..]
      })
    },
    func(c upgrade.Context) {
      ksvc := e2e.Clients.Knative.Serving.Namespace(namespace).Get(service)
      // do a checking
    },
  )
}

and example test that uses it:

// +build upgrade
// file: knative.dev/serving/test/e2e/upgrade_test.go
package e2e

import (
  "testing"

  "go.uber.org/zap"
  "knative.dev/pkg/test/upgrade"
  serving "knative.dev/serving/test/e2e/upgrade"
)

func TestServingUpgradesDowngrades(t *testing.T) {
  suite := upgrade.Suite{
    Tests: upgrade.Tests{
      PreUpgrade: []upgrade.Operation{
        serving.SmokeTest(),
      },
      PostUpgrade: []upgrade.Operation{
        serving.SmokeTest(),
      },
      PostDowngrade: []upgrade.Operation{
        serving.SmokeTest(),
      },
      Continual: []upgrade.BackgroundOperation{
        serving.ContinualTest(),
      },
    },
    Installations: upgrade.Installations{
      Base: []upgrade.Operation{
        serving.InstallLatestStable(),
      },
      UpgradeWith: []upgrade.Operation{
        serving.GitHead(),
      },
      DowngradeWith: []upgrade.Operation{
        serving.InstallLatestStable(),
      },
    },
  }
  c := newUpgradeConfig(t)
  suite.Execute(c)
}

func newUpgradeConfig(t *testing.T) upgrade.Configuration {
  log, err := zap.NewDevelopment()
  if err != nil {
    t.Fatal(err)
  }
  return upgrade.Configuration{T: t, Log: log}
}

@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 27, 2020
@knative-prow-robot
Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@knative-prow-robot knative-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 27, 2020
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Aug 27, 2020
Copy link
Copy Markdown
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -name '*.pb.go' -prune -o -type f -name '*.go' -print)
goimports -w $(find -name '*.go' | grep -v vendor | grep -v third_party | grep -v .pb.go | grep -v wire_gen.go)

@cardil cardil force-pushed the feature/upgrade-test-framework branch from 175462c to f11a5e9 Compare August 27, 2020 13:42
Comment thread test/upgrade/execute.go Outdated
Comment thread test/upgrade/operations.go Outdated
Copy link
Copy Markdown
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -name '*.pb.go' -prune -o -type f -name '*.go' -print)
goimports -w $(find -name '*.go' | grep -v vendor | grep -v third_party | grep -v .pb.go | grep -v wire_gen.go)

Comment thread test/upgrade/execute.go Outdated
Comment thread test/upgrade/operations.go Outdated
Comment thread test/upgrade/operations.go
@knative-prow-robot knative-prow-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 2, 2020
Copy link
Copy Markdown
Contributor

@mgencur mgencur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cardil , I think this looks great! Like it very much. I've put some comments here and there. There's probably some room for improvement to make it slightly cleaner or easier for the implementor of the background operations. Thanks!

Comment thread test/upgrade/execute.go Outdated
Comment thread test/upgrade/execute_test.go Outdated
Comment thread test/upgrade/operations.go Outdated
Comment thread test/upgrade/types.go Outdated
Comment thread test/upgrade/types.go
Comment thread test/upgrade/types.go Outdated
Comment thread test/upgrade/operations.go Outdated
Comment thread test/upgrade/execute_test.go Outdated
Comment thread test/upgrade/types.go Outdated
Comment thread test/upgrade/types.go
@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 3, 2020
@cardil cardil force-pushed the feature/upgrade-test-framework branch from 5c13294 to 3e6301e Compare September 3, 2020 18:17
A StopSignal has been splitted to 2 separate type private stoppable and
a StopEvent. StopEvent contains only elements that are essential for
implementors to use *testing.T and signalize end of stop & verify
procedure to upgrade suite.
Comment thread test/upgrade/asserts_test.go
Comment thread test/upgrade/types.go Outdated
Comment thread test/upgrade/types.go
Comment thread test/upgrade/testing_operations_test.go Outdated
Comment thread test/upgrade/testing_operations_test.go
Functions NewBackgroundVerification and WaitForStopEvent has
been introduced to ease implementers to write a simple setup &
verify background tests.
@cardil cardil marked this pull request as ready for review September 9, 2020 12:46
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 9, 2020
Comment thread test/upgrade/types.go Outdated
Comment thread test/upgrade/zaptest_buffer_test.go
@knative-metrics-robot
Copy link
Copy Markdown

The following is the coverage report on the affected files.
Say /test pull-knative-pkg-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
test/upgrade/functions.go Do not exist 100.0%
test/upgrade/steps.go Do not exist 95.5%
test/upgrade/suite_execution.go Do not exist 94.3%
test/upgrade/vars.go Do not exist N/A

@mgencur
Copy link
Copy Markdown
Contributor

mgencur commented Sep 11, 2020

@cardil thanks for all the changes! I think it looks good now. Looking forward to using that.

@mgencur
Copy link
Copy Markdown
Contributor

mgencur commented Sep 11, 2020

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 11, 2020
@chizhg
Copy link
Copy Markdown
Contributor

chizhg commented Sep 18, 2020

/approve

@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cardil, chizhg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 18, 2020
@knative-prow-robot knative-prow-robot merged commit 6ce80a7 into knative:master Sep 18, 2020
@cardil cardil deleted the feature/upgrade-test-framework branch September 19, 2020 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/test-and-release cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade tests pluggable test suite

9 participants