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

Mark E2E plumbing as test helpers #421

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

negz
Copy link
Contributor

@negz negz commented Jun 4, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

In Crossplane we try to use reusable step functions in our E2E tests, so they end up looking like this:

func TestExample(t *testing.T) {
	environment.Test(t,
		features.New(t.Name()).
			WithSetup("ExampleSetup", funcs.SomeSetupFn()).
			Assess("ExampleAssess", funcs.SomeAssessFn()).
			WithTeardown("ExampleTeardown", funcs.SomeTearDownFn()).
			Feature(),
	)
}

Since step functions are passed *testing.T we'll often call t.Error, t.Log, etc from our step functions. These testing calls include the call point (i.e. filename and line number) in their output. Without using t.Helper() the call point will be the file where the step function is defined (e.g. features.go) rather than the calling test.

We want to mark our step functions as test helpers using t.Helper so that the calling test is included in the output. For this to work we need to mark all the intermediary plumbing functions and methods in e2e-framework as helpers too.

Which issue(s) this PR fixes:

I didn't raise an issue tracking this.

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Internal machinery used to call step functions is now marked as test helpers. This means you can mark your step functions as a test helper using `t.Helper()`, and test logs will be include the filename and line number of `environment.Test()` call.

Additional documentation e.g., Usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Jun 4, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @negz!

It looks like this is your first PR to kubernetes-sigs/e2e-framework 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/e2e-framework has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 4, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @negz. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 4, 2024
@negz negz force-pushed the helpy-helpington branch from ab485ba to e8d79af Compare June 4, 2024 21:06
@negz negz changed the title Helpy helpington Mark E2E plumbing as test helpers Jun 4, 2024
@sttts
Copy link
Contributor

sttts commented Jun 4, 2024

Is this actually helping? t.Helper() just removes one frame of the stack. I.e. you see the file+line of the parent (or some ancestor) during execution of the closure returned by funcs.SomeAssessFn(), not during execution of funcs.SomeAssessFn. So you will not know which of the funcs.SomeAssessFn failed, but only the file (and test).

@sttts
Copy link
Contributor

sttts commented Jun 4, 2024

I see that you comment exactly that in crossplane/crossplane#5722 (comment). So this PR is better than nothing clearly.

@vladimirvivien
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-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 24, 2024
Copy link
Contributor

@vladimirvivien vladimirvivien left a comment

Choose a reason for hiding this comment

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

This is great @negz . Any side effects of calling t.Helper() successively on the same *testing.T value ?

cc @harshanarayana

@vladimirvivien
Copy link
Contributor

Apologies for the late review on this folks.

@negz
Copy link
Contributor Author

negz commented Jun 26, 2024

@vladimirvivien Not that I know of. I believe it's pretty normal to call it repeatedly (e.g. if you have several layers of test helper functions).

@harshanarayana
Copy link
Contributor

/retest

@harshanarayana
Copy link
Contributor

@vladimirvivien Calling the t.Helper multiple times should be ok. It Should be using the current frames to do the analysis.

package abc

import (
	"os"
	"testing"
)

func TestMain(m *testing.M) {
	os.Exit(m.Run())
}

func assertSomething(t *testing.T, a int) {
	t.Helper()
	t.Error("something failed")
}

func TestSomething(t *testing.T) {
	data := []int{
		1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
	}

	for tc := range data {
		assertSomething(t, tc)
	}
}

Copy link
Contributor

@harshanarayana harshanarayana left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 26, 2024
Copy link
Member

@cpanato cpanato left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 26, 2024
@harshanarayana
Copy link
Contributor

/retest

@vladimirvivien
Copy link
Contributor

/lgtm

@vladimirvivien
Copy link
Contributor

/retest

@vladimirvivien
Copy link
Contributor

This is failing consistently it seems, is there a regression ?

/retest

@harshanarayana
Copy link
Contributor

@vladimirvivien seems like a flaky test. Let me take a look.

@harshanarayana
Copy link
Contributor

/approve

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2024
@cpanato
Copy link
Member

cpanato commented Jul 9, 2024

@negz can you please rebase and fix the conflicts? thanks

This results in the environment.Test call point being used as the file
and line number in test logs, failures, etc.

Signed-off-by: Nic Cope <[email protected]>
@negz negz force-pushed the helpy-helpington branch from e8d79af to 1e6b6ea Compare July 9, 2024 18:21
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 9, 2024
@harshanarayana
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 11, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cpanato, harshanarayana, negz

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:
  • OWNERS [cpanato,harshanarayana]

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

@harshanarayana
Copy link
Contributor

/retest

@k8s-ci-robot k8s-ci-robot merged commit db6a005 into kubernetes-sigs:main Jul 11, 2024
4 checks passed
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", 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. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants