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: dedup Before/AfterEach nodes #18544

Merged
merged 1 commit into from
May 15, 2023

Conversation

Luap99
Copy link
Member

@Luap99 Luap99 commented May 11, 2023

There is no reason to define the same code every time in each file, just use global nodes. This diff should speak for itself.

Does this PR introduce a user-facing change?

None

@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 11, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 11, 2023
@Luap99 Luap99 mentioned this pull request May 11, 2023
13 tasks
@rhatdan
Copy link
Member

rhatdan commented May 12, 2023

Nice simplification
LGTM
@edsantiago PTAL

@TomSweeneyRedHat
Copy link
Member

Big Gold Star for this one @Luap99 🌟
@edsantiago PTAL
LGTM, but let's let Ed merge this

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

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

I really love this, thank you! I'm concerned about the ordering of AfterEach(). (BeforeEach(), it seems clear that common runs before the test-specific one). Specifically, in tests where cleanup involves Unsetenv("CONTAINERS_CONF"), can you confirm that the ordering of Unsetenv()-Cleanup() is safe, or does not matter? Also, the Volumes thing below.

Thank you for taking this on!

@Luap99
Copy link
Member Author

Luap99 commented May 15, 2023

Specifically, in tests where cleanup involves Unsetenv("CONTAINERS_CONF"), can you confirm that the ordering of Unsetenv()-Cleanup() is safe, or does not matter?

It most cases it does not matter, however while working on ginkgov2 I found a case where it matters. When tests use an invalid CONTAINERS_CONF file which contains invalid options or maybe does not even exists podman will just error out. Thus the Cleanup() could fail in this case. Therefore the correct order is to always unsetenv before Cleanup().

@Luap99
Copy link
Member Author

Luap99 commented May 15, 2023

given how many tests use CONTAINERS_CONF I could juts move it in the main AfterEach() block and let all test unset it. There shouldn't be a problem with that and it prevents other from forgetting to unset it.

@edsantiago
Copy link
Member

Seems fair. I did a very quick check, and don't see any places where Cleanup() would require the test's CONTAINERS_CONF, but I don't fully trust myself to be certain. This is tricky.

@edsantiago
Copy link
Member

This is a lot cleaner and looks safer, thank you! Thanks for documenting the execution order and for the link. A few typos in the commit message, not worth re-pushing for, but if a re-push is needed for anything else, please take a quick edit pass there.

processTestResult(f)

// make sure connections are not written to real user config on host
os.Setenv("CONTAINERS_CONF", filepath.Join(podmanTest.TempDir, "containersconf"))
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you need to create this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Guess I deserve that for not running it locally first.

@edsantiago
Copy link
Member

Ginkgo orders the BeforeEach and AfterEach nodes. They will be executed
from the outer-most defnied to inner-most. This mean out global

"defined"; "our"

BeforeEAch is always first. Only then the inner one (in the Describe() funtion

"Each"; "function"

There is no reason to define the same code every time in each file, just
use global nodes. This diff should speak for itself.

CleanupSecrets()/Volume() no longer call Cleanup() directly, as the
global AfterEach node will always call Cleanup() this is no longer
necessary. If one AfterEach() node fails it will still run the others.

Also always unset the CONTAINERS_CONF env vars. This prevents people
from forgetting to unset it. And fix the special CONTAINERS_CONF logic
in the system connection tests, we do not want to preserve
CONTAINERS_CONF anyway so just remove this logic.

Ginkgo orders the BeforeEach and AfterEach nodes. They will be executed
from the outer-most defined to inner-most. This means our global
BeforeEach is always first. Only then the inner one (in the Describe()
function in each file). For AfterEach it is inverted, from the inner to
the outer.
Also see https://onsi.github.io/ginkgo/#organizing-specs-with-container-nodes

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
@edsantiago
Copy link
Member

/lgtm
/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 15, 2023
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label May 15, 2023
@edsantiago
Copy link
Member

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 15, 2023
@openshift-merge-robot openshift-merge-robot merged commit 7d305d5 into containers:main May 15, 2023
@Luap99 Luap99 deleted the e2e-dedup branch May 15, 2023 16:56
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Aug 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants