Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the support to test against specified release of Knative serving #170

Merged
merged 1 commit into from
Jun 28, 2019
Merged

Add the support to test against specified release of Knative serving #170

merged 1 commit into from
Jun 28, 2019

Conversation

houshengbo
Copy link

@houshengbo houshengbo commented Jun 7, 2019

This PR adds an environment variable $KNATIVE_VERSION for both e2e-tests.sh and presubmit-tests.sh, in order to specify the version of Knative serving to be installed.

Closes: #168

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jun 7, 2019
@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 7, 2019
@knative-prow-robot
Copy link
Contributor

Hi @houshengbo. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 7, 2019
@houshengbo houshengbo changed the title Add the support test against the previous release and the latest source Add the support to test against the previous release and the latest source Jun 7, 2019
@houshengbo
Copy link
Author

/assign @sixolet @rhuss

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Thanks ! I have some suggestion to discuss wrt/ organizing the script.

start_latest_knative_serving
}
export KNATIVE_SERVING_VERSION=latest
source $(dirname $0)/e2e-common.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of sourcing the same file twice, could we put the actual test code into a reusable function which gets the target version as argument?

Its easier to maintain if you transport the input to a function with arguments and not global environment variables (which also avoid unwanted side effects because of this global state), and you can reuse it much easier e.g. when you want to add another version.

Therefore I would also roll up the code into a loop which makes it more concise.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

Copy link
Author

Choose a reason for hiding this comment

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

Done.


initialize $@

header "Running tests"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we output the version to test again here, too ? Makes it easier to analyse test failures.

# Helper functions.

function knative_setup() {
start_release_knative_serving "$KNATIVE_SERVING_VERSION"
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that this callback function is only easy to customize with an environment variable (as you can't change the signature). However, you could put this kind of implementation detail inside the function that is called from outside this script so that you can avoid to source this file twice.

Copy link
Author

@houshengbo houshengbo Jun 10, 2019

Choose a reason for hiding this comment

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

This function knative_setup
is called by source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/e2e-tests.sh.

It has to be defined after source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/e2e-tests.sh. Am I correct?

If it is defined in e2e-tests.sh with soucing github.com/knative/test-infra/scripts/e2e-tests.sh, I do not think it will be called.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tbh, I don't think that e2e-tests.sh execute any codes, but only defines functions which can be called later. Otherwise knative_setup would have to be defined before sourcing this file

As a rule of thumb: Any shell script which is source must only define functions or global environment variables (if they have to).

./kn service delete hello || fail_test
./kn service delete foo || fail_test
success
export KNATIVE_SERVING_VERSION=$PREVIOUS_RELEASE
Copy link
Contributor

Choose a reason for hiding this comment

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

To be more concrete, my suggestion would be something along those lines:

  • e2e-tests.sh:
sourcce e2e-commons.sh
for version in latest $PREVIOUS_RELEASE; do
   echon "===== Starting E2E tests for $version
   run_tests $version
done
  • e2e-common.sh:
run_tests() {
  local $version=${1}
  export KNATIVE_SERVING_VERSION=$version
  initialize

  header "[$version]: Running tests"

  kn_tests  
}


kn_tests() {
  ./kn service create hello --image gcr.io/knative-samples/helloworld-go -e TARGET=Knative ||   fail_test
  sleep 5
  ./kn service get || fail_test
  ./kn service update hello --env TARGET=kn || fail_test
  sleep 3
  ./kn revision get || fail_test
  ./kn service get || fail_test
  ./kn service create hello --force --image gcr.io/knative-samples/helloworld-go -e   TARGET=Awesome || fail_test
  ./kn service create foo --force --image gcr.io/knative-samples/helloworld-go -e TARGET=foo ||   fail_testa
  sleep 5
  ./kn revision get || fail_test
  ./kn service get || fail_test
  ./kn service describe hello || fail_test
  ./kn service delete hello || fail_test
  ./kn service delete foo || fail_test
  success
}

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Thanks a lot for putting the test code in functions. However, as mentioned in the review we must not couple ourselves to the internal functions of the e2e library.

I opened knative/test-infra#897 for updating the upstream script to allow a parameterization of the Knative installation against which we want to install.

# This method is copied from github.com/knative/test-infra/scripts/e2e-tests.sh, since the original var
# $KNATIVE_SERVING_RELEASE is readonly. In order to make it changeable, we rewrite the method with another
# variable $KNATIVE_SERVING_RELEASE_YAML.
function start_release_knative_serving() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see your motivation but we shouldn't do this, because:

  • We don't benefit from changes in this method upstream
  • When the overridden function gets renamed the script fails silently (because this method is just not called).

Instead we should push a change upstream to make the version to install parameterizable either via an argument or an environment variable.

Tbh I think its even a fault that this method can be overridden. This subtle coupling is really hard to debug.

Let me open an issue in the testing upstream repo.

Copy link
Author

Choose a reason for hiding this comment

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

Yep, it is good to see test-infra is able to support the installation of custom release number.

@rhuss
Copy link
Contributor

rhuss commented Jun 11, 2019

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 11, 2019
@houshengbo
Copy link
Author

/retest

}

echo "===== Starting E2E tests for Knative serving of the release $KNATIVE_SERVING_VERSION"
run_tests $@
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the function call which will trigger everything. Up to this point, everything needs to be defined/sourced.

Copy link
Contributor

Choose a reason for hiding this comment

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

As I expect e22-common.sh to be a kind of library it should also only contain function definitions but must not call or execute any command when being included.

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Thanks, you are heading in the right direction. However, you should take care to only call the final execution function run_tests in the outermost script, not by calling or sourcing an external script. See the comments inline.

}

echo "===== Starting E2E tests for Knative serving of the release $KNATIVE_SERVING_VERSION"
run_tests $@
Copy link
Contributor

Choose a reason for hiding this comment

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

As I expect e22-common.sh to be a kind of library it should also only contain function definitions but must not call or execute any command when being included.

success
for version in "${listOfRelease[@]}"; do
export KNATIVE_SERVING_VERSION=$version
$(dirname $0)/e2e-common.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of calling out to e2e-commons.sh, call here run_tests $@ and source all function definitions before.

# Helper functions.

function knative_setup() {
start_release_knative_serving "$KNATIVE_SERVING_VERSION"
Copy link
Contributor

Choose a reason for hiding this comment

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

Tbh, I don't think that e2e-tests.sh execute any codes, but only defines functions which can be called later. Otherwise knative_setup would have to be defined before sourcing this file

As a rule of thumb: Any shell script which is source must only define functions or global environment variables (if they have to).

@rhuss
Copy link
Contributor

rhuss commented Jun 17, 2019

The integration tests fails with a

I0617 01:33:17.642] 2019/06/17 01:33:17 process.go:155: Step '/go/src/github.com/knative/client/test/e2e-common.sh --run-tests' finished in 1m17.206419171s
I0617 01:33:17.658] 2019/06/17 01:33:17 main.go:312: Something went wrong: encountered 1 errors: [error during /go/src/github.com/knative/client/test/e2e-common.sh --run-tests: signal: segmentation fault (core dumped)]
I0617 01:33:17.714] Test subprocess exited with code 1

(not sure where this comes from) and the client test fails because the deps have not been updated.

@houshengbo could you please run a hack/build.sh -u and commit the updated modules.txt to fix the client test ?

Let's hope that the integration test failure is just a flake.

@houshengbo
Copy link
Author

@rhuss Thanks for your comments. I am thinking of another way to fix this issue.
For the repo of knative client, I would like to add the support of a param, so that e2e-tests.sh can either run against the latest build or a previous release.
Then, we need to make the integration job of pull-knative-client-integration-tests to test both the latest and previous release. Instead of running test/e2e-tests.sh once, we can two builds, like
./test/e2e-tests.sh latest and ./test/e2e-tests.sh 0.6.0.
It is not quite friendly to run tests against two knative installations on local machines. Folks are a sort of forced to run twice of the setup and integration tests.
What do you think?

@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 17, 2019
@rhuss
Copy link
Contributor

rhuss commented Jun 17, 2019

What do you think?

yes, sounds good to me. Also if we could configure that as two different GitHub checks then it would be evident which one is failing. Also it helps in parallelizing the tests which should it make faster.

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 17, 2019
@houshengbo houshengbo changed the title Add the support to test against the previous release and the latest source Add the support to test against specified previous release Jun 17, 2019
@rhuss
Copy link
Contributor

rhuss commented Jun 28, 2019

@houshengbo There are some minor merge conflicts. Could you please fix them? I will review the PR in the meantime. Thanks !

@knative-prow-robot knative-prow-robot removed the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 28, 2019
@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 28, 2019
Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

See my comments below.

And I would rename the variable to KNATIVE_SERVING_VERSION as it is really about installing Knative Serving (and we might want to have different numbers for Knative eventing when it enters the client)

test/e2e-tests.sh Outdated Show resolved Hide resolved

# Script entry point.

initialize $@

header "Running tests"
header "Running tests for Knative serving version of $KNATIVE_VERSION"
Copy link
Contributor

Choose a reason for hiding this comment

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

"Running tests for Knative serving $KNATIVE_VERSION"

Copy link
Author

Choose a reason for hiding this comment

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

Done.

test/e2e-tests.sh Outdated Show resolved Hide resolved
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really get this file (but could be also my ignorance ;)

  • Shouldn't it be called '...latest-release.sh' as it refers to the latest release whereas "latest" refers to HEAD of master (unreleased code). A bit confusing. Or maybe call it really with the version number ('presubmit-integration-tests-0.6.0.sh') and update the configuration that calls this file
  • Who is calling this file ?
  • Why it is calling presubmit checks and not the e2e tests like in e2e-tests.sh but with a environment variable set ?

Copy link
Contributor

Choose a reason for hiding this comment

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

So I would have expected something like

export KNATIVE_VERSION="0.6.0"
$(dirname $0)/e2e-tests.sh

Copy link
Contributor

Choose a reason for hiding this comment

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

Talked offline with @houshengbo . It's complicated (as the second job needs to be a custom job).

Copy link
Author

@houshengbo houshengbo Jun 28, 2019

Choose a reason for hiding this comment

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

Thank @rhuss for his suggestion. We will use latest-release.
The repo test-infra defines four basic type of jobs, every PR can enable: integration-tests, build-tests, go-coverage, and unit-tests. We can only have four regular jobs, with one for each of them respectively. It means even if we would like to have a new INTEGRATION TEST, we need to go through CUSTOM TEST JOB in test-infra. We cannot use the existing presubmit-tests.sh --integration-tests with more argument to specify the version or anything else, and we cannot use extra argument for command in CUSTOM TEST either. That was the reason we needed to have a separate script like this one, with the correct env var setting for a specific version, to launch separately with a CUSTOM TEST JOB in test-infra. BTW, another PR for test-infra related to this PR is knative/test-infra#954.

@houshengbo houshengbo changed the title Add the support to test against specified previous release Add the support to test against specified release of Knative serving Jun 28, 2019
@rhuss
Copy link
Contributor

rhuss commented Jun 28, 2019

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 28, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: houshengbo, rhuss

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

The pull request process is described here

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 Jun 28, 2019
@rhuss
Copy link
Contributor

rhuss commented Jun 28, 2019

Thanks !

@knative-prow-robot knative-prow-robot merged commit 663d76a into knative:master Jun 28, 2019
maximilien pushed a commit to maximilien/client that referenced this pull request Jul 1, 2019
coryrc pushed a commit to coryrc/client that referenced this pull request May 14, 2020
* Create a helper for running e2e go tests

Let's hide the complexity of running e2e go tests in `e2e-tests.sh`.

Bonus: move documentation to `README.md` to make it more visible.

Part of knative#170.

* Add kubectl call to example
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test against most recent Serving release && HEAD
5 participants