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

test/e2e/common/node: enhance assertions #110127

Merged
merged 1 commit into from May 25, 2022

Conversation

jwtty
Copy link
Member

@jwtty jwtty commented May 19, 2022

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Better output for developers when tests fail.

Which issue(s) this PR fixes:

Fixes part of #105678

Special notes for your reviewer:

After this PR:

.../kubernetes/test/e2e/common/node$ git grep 'Expect.*Equal([^,]*, *\(true\|false\)' | wc -l
0

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 19, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @jwtty!

It looks like this is your first PR to kubernetes/kubernetes 🎉. 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/kubernetes 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 needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 19, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @jwtty. Thanks for your PR.

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

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label May 19, 2022
@k8s-ci-robot k8s-ci-robot added area/test sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 19, 2022
@jwtty
Copy link
Member Author

jwtty commented May 19, 2022

/assign @pohly

Copy link
Contributor

@pohly pohly left a comment

Choose a reason for hiding this comment

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

/ok-to-test

Thanks for taking care of this. Some initial comments, still need to go through the entire diff...

test/e2e/common/node/init_container.go Outdated Show resolved Hide resolved
test/e2e/common/node/init_container.go Show resolved Hide resolved
@@ -89,7 +89,9 @@ var _ = SIGDescribe("Lease", func() {

readLease, err := leaseClient.Get(context.TODO(), name, metav1.GetOptions{})
framework.ExpectNoError(err, "couldn't read Lease")
framework.ExpectEqual(apiequality.Semantic.DeepEqual(lease.Spec, readLease.Spec), true)
if !apiequality.Semantic.DeepEqual(lease.Spec, readLease.Spec) {
framework.Failf("expected lease spec: %#v, got %#v", lease.Spec, readLease.Spec)
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have good pretty-printing of API objects. Gomega's format.Object indents them nicely, but prints empty fields. There's a discussion going elsewhere about that.

I don't have a strong opinion about printf-style format strings. Can you perhaps try out which looks best (%s, %+v, %#v)?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we print as a single line, the printing the two objects on top of each other is easier to compare:
"Leases don't match. Expected:\n\t%s\nActual:\n\t%s"

Copy link
Member Author

Choose a reason for hiding this comment

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

I wrote a piece of code to experiment:

s1 := spec{
		HolderIdentity:       sPtr("holder"),
		LeaseDurationSeconds: iPtr(30),
		AcquireTime:          &microTime{Time: time.Time{}.Add(2 * time.Second)},
		RenewTime:            &microTime{Time: time.Time{}.Add(5 * time.Second)},
		LeaseTransitions:     iPtr(0),
}
fmt.Printf("%#v\n", s1)
fmt.Println("=====================")
fmt.Printf("%s\n", s1)
fmt.Println("=====================")
fmt.Printf("%+v", s1)

And result is:

main.spec{HolderIdentity:(*string)(0xc000010250), LeaseDurationSeconds:(*int32)(0xc000018030), AcquireTime:time.Date(1, time.January, 1, 0, 0, 2, 0, time.UTC), RenewTime:time.Date(1, time.January, 1, 0, 0, 5, 0, time.UTC), LeaseTransitions:(*int32)(0xc000018034)}
=====================
{%!s(*string=0xc000010250) %!s(*int32=0xc000018030) 0001-01-01 00:00:02 +0000 UTC 0001-01-01 00:00:05 +0000 UTC %!s(*int32=0xc000018034)}
=====================
{HolderIdentity:0xc000010250 LeaseDurationSeconds:0xc000018030 AcquireTime:0001-01-01 00:00:02 +0000 UTC RenewTime:0001-01-01 00:00:05 +0000 UTC LeaseTransitions:0xc000018034}

I personally prefer the %+v output, informative enough and not too long. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, let's use that.

Copy link
Contributor

Choose a reason for hiding this comment

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

However, it won't help to diagnose the problem. It's better than before, but not good enough. For example, if HolderIdentity is different, then the output will just show the addresses, not the string.

Perhaps Failf should show the result of https://github.com/google/go-cmp?

Copy link
Member

Choose a reason for hiding this comment

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

go-cmp would be much better there 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I switched to use go-cmp.

@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 May 19, 2022
Copy link
Member

@endocrimes endocrimes 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 much uglier code for not a meaningful test output improvement but logic looks fine.

We should consider ExpectTrue/ExpectFalse helpers that can skip the slightly uglier comparison output, but not litter the code base with if THING { fail... }.

test/e2e/common/node/container_probe.go Outdated Show resolved Hide resolved
test/e2e/common/node/container_probe.go Outdated Show resolved Hide resolved
test/e2e/common/node/container_probe.go Outdated Show resolved Hide resolved
test/e2e/common/node/secrets.go Outdated Show resolved Hide resolved
test/e2e/common/node/secrets.go Outdated Show resolved Hide resolved
@endocrimes
Copy link
Member

/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 22, 2022
@pohly
Copy link
Contributor

pohly commented May 22, 2022

This is much uglier code

I think that's subjective. I find the if check easier to read than the ExpectEqual(xxx, true/false).

for not a meaningful test output improvement

It might not have more meaning, but it's at least less distracting because it is just the failure message without the "expected false to be true" boilerplate.

FWIW, I agree with your suggestions to enhance the failure messages while touching the code.

@jwtty
Copy link
Member Author

jwtty commented May 22, 2022

Thanks for the comments. I'm working on improving the error msgs.

Copy link
Member

@endocrimes endocrimes left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

thank you!

@endocrimes endocrimes moved this from Triage to Done in SIG Node CI/Test Board May 25, 2022
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 25, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: endocrimes, jwtty

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 25, 2022
@pohly
Copy link
Contributor

pohly commented May 25, 2022

/retest

1 similar comment
@pohly
Copy link
Contributor

pohly commented May 25, 2022

/retest

@k8s-ci-robot k8s-ci-robot merged commit b099151 into kubernetes:master May 25, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.25 milestone May 25, 2022
@jwtty jwtty deleted the boolcheck branch May 26, 2022 03:19
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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants