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

RFC: Introduce PodmanTestIntegration.PodmanCleanly #24977

Merged
merged 2 commits into from
Jan 10, 2025

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Jan 8, 2025

This significantly simplifies the ceromony of running a Podman command in integration tests, from

  session := p.Podman([]string{"stop", id})
  session.WaitWithDefaultTimeout()
  Expect(session).Should(ExitCleanly())

to

  p.PodmanCleanly("stop", id)

There are >4650 instances of ExitCleanly() in the tests, and many could be migrated; this does not do that.

@containers/podman-maintainers RFC. While writing integration tests, I find the ever-present repetitive boilerplate hard to read/maintain, and generally off-putting; OTOH the PodmanCleanly call does not show explicitly that any testing is happening. I’m also, short-term, not able to migrate everything, so introducing this would make tests less consistent for now.

It’s also very possible there’s already a much better way to do things, and I just don’t know.

Does this PR introduce a user-facing change?

None

@openshift-ci openshift-ci bot added release-note-none approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 8, 2025
@mtrmac
Copy link
Collaborator Author

mtrmac commented Jan 8, 2025

I’m also 100% open to suggestions of a better name of the helper.

@rhatdan
Copy link
Member

rhatdan commented Jan 8, 2025

I think PodmanExitCleanly() would be a better name.
But this is a good idea.
LGTM

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM, we can incrementally move new tests to the new function.

I also think PodmanExitCleanly is a bit more descriptive

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

I also prefer PodmanExitCleanly as name. Otherwise I think this is a good idea and I don't see a strict need to manually convert all callers right now.
We can start using it for new code only.

func (p *PodmanTestIntegration) PodmanCleanly(args ...string) *PodmanSessionIntegration {
session := p.Podman(args)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Copy link
Member

Choose a reason for hiding this comment

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

This should use ExpectWithOffset(1,...), the last line in the stack trace in the log will otherwise all point to this line here which is pretty pointless as I like to get linked to the actual command that failed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Trying GinkgoHelper — that should also affect the failures in WaitWithDefaultTimeout.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes that seems much better than having to deal with correct offset numbers.

@mheon
Copy link
Member

mheon commented Jan 9, 2025

I like it. LGTM once the comment from @Luap99 is addressed.
I would like to see an existing file migrated (one of the smaller ones) to see what this looks like in practice, but see no need to do this in this PR.

@baude
Copy link
Member

baude commented Jan 9, 2025

what do people think about the inverse as well? PodmanExitFailure which takes a command and an exit code?

@baude
Copy link
Member

baude commented Jan 9, 2025

I like it. LGTM once the comment from @Luap99 is addressed. I would like to see an existing file migrated (one of the smaller ones) to see what this looks like in practice, but see no need to do this in this PR.

If @mtrmac repushes, I can rebase and use in the artifact e2e tests happily.

@Luap99
Copy link
Member

Luap99 commented Jan 9, 2025

what do people think about the inverse as well? PodmanExitFailure which takes a command and an exit code?

It would need to take an error message as well (exit code checks are useless without proper error message checks) and then at that point the lines gets so long that it needs to be split on multiple lines anyway so then it is no longer that much shorter. Although I guess getting rid of the WaitWithDefaultTimeout() timeout calls would help a fair bit still

@mtrmac
Copy link
Collaborator Author

mtrmac commented Jan 9, 2025

Updated:

  • Renamed to PodmanExitCleanly
  • Updated attach_test.go to show what this looks like (notably how the PodmanExitCleanly calls look a bit different from raw Podman calls when we expect failure or want some extra processing).
  • Marked the new utility as a helper.

It seems to me that the command tests might be possible to express in some more concise way with a builder-like API:

/* session = */ p.Podman("system", "reset", "-f") // default: run command, default timeout, expect success

/* session = */ p.Command("skopeo", "--version") // other command, default timeout, expect success

/* session = */ p.PodmanWithOptions("other", "situations").Options(
    WithTimeout(other),
    ExpectError(code, string),
    DoNotExecute(), // for truly custom situations
    NoEvents(), // instead of the PodmanBase / Podman split
    …
)

but, also, we are not in the business of inventing a new integration test DSL. There’s a balance to be struck; the sweet spot is probably being a bit more expressive / capable than just PodmanExitCleanly (for non-Podman commands and common error situations?), but not much more expressive, adding dozens of new helpers.

If nothing else, I think that using ...string instead of having []string{} on every call site is an obvious improvement that could happen in more situations.

Anyway, this is not something I can work on right now. I just wanted to avoid the very obvious boilerplate when writing a few hundred lines of new tests.

mtrmac added 2 commits January 9, 2025 18:47
This significantly simplifies the ceromony of running a Podman command
in integration tests, from

> session := p.Podman([]string{"stop", id})
> session.WaitWithDefaultTimeout()
> Expect(session).Should(ExitCleanly())

to
> p.PodmanExitCleanly("stop", id)

There are >4650 instances of ExitCleanly() in the tests,
and many could be migrated; this does not do that.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
just as a demonstration.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

openshift-ci bot commented Jan 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe, Luap99, mtrmac

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 [Luap99,giuseppe,mtrmac]

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

@rhatdan
Copy link
Member

rhatdan commented Jan 10, 2025

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 1194557 into containers:main Jan 10, 2025
56 checks passed
@mtrmac mtrmac deleted the exitcleanly branch January 10, 2025 20:24
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. lgtm Indicates that a PR is ready to be merged. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants