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

Integration tests: run git daemon on a random-but-bind()able port #5783

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

nalind
Copy link
Member

@nalind nalind commented Oct 16, 2024

What type of PR is this?

/kind flake

What this PR does / why we need it:

Use a listener helper to bind to an available-according-to-the-kernel listening port and run a command with its stdio more or less tied to the connection instead of trying to launch a git daemon directly using a port number that we can only guess is available.

How to verify it

Our build-using-a-git-context tests should continue to pass.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

Does this PR introduce a user-facing change?

None

@openshift-ci openshift-ci bot added kind/flake Categorizes issue or PR as related to a flaky test. approved labels Oct 16, 2024
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.

This looks like a bit overkill, in podman we have this long solved by using random_free_port() which seem to hold up fine there.
https://github.com/containers/podman/blob/740f1d1fc710d4560d2463b11333cc9ad68e22bd/test/system/helpers.network.bash#L306-L329

I think this is simpler for test issues to debug then dealing with custom written binary that can fail in a lot of unexpected ways. It will also means we would have to ship this binary in the test package for gating tests

@nalind
Copy link
Member Author

nalind commented Oct 18, 2024

Now that I know about it, it's tempting, but it's not appreciably shorter, and debugging Go code is easier than attempting to copy and keep up-to-date shell functions that live in a different repository.
Taking tests that were written here, incorporating and reusing them elsewhere, and then expecting them to not require any upkeep, is an unrealistic expectation to place on any project. I can add the helper binary to the .spec file, though, that's simple enough.

@Luap99
Copy link
Member

Luap99 commented Oct 18, 2024

Well debugging this custom go code may be easier for you but I doubt it is easier for the person running these tests on gating env that have to look at any failures and make sense of them such as @edsantiago.

In any case you are the main maintainer here and I am certainly not going to block this if it helps to solve a flake.

args := flag.Args()
if len(args) < 1 {
fmt.Printf("Usage: %s [-port-file filename] [-pid-file filename] command ...\n", filepath.Base(os.Args[0]))
return
Copy link
Member

Choose a reason for hiding this comment

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

should this exit(1)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, probably. Changing it.

return
}
// Start listening without specifying a port number.
ln, err := net.ListenTCP("tcp", &net.TCPAddr{})
Copy link
Member

Choose a reason for hiding this comment

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

would it make sense to at least bind 127.0.0.1, there seems little reason to expose this externally

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, leaving it empty means we don't have to care about ipv4/ipv6 here, though.

Copy link
Member

Choose a reason for hiding this comment

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

I mean fair enough, it should not be a problem though as all test connect to localhost which generally should try both ::1 and 127.0.0.1 so I doubt it causes issues.

Comment on lines 44 to 49
colon := strings.LastIndex(addrString, ":")
if colon == -1 {
logrus.Fatalf("finding the start of the port number in %q", addrString)
}
// Write the port number part to the specified file, if one was specified.
portString := addrString[colon+1:]
Copy link
Member

Choose a reason for hiding this comment

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

you can use net.SplitHostPort()

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, nice. Switching to it.

@@ -110,6 +110,9 @@ bin/copy: $(SOURCES) tests/copy/copy.go
bin/tutorial: $(SOURCES) tests/tutorial/tutorial.go
$(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/tutorial/tutorial.go

bin/inet: tests/inet/inet.go
Copy link
Member

Choose a reason for hiding this comment

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

This will need to be shipped in the buildah-tests package, presumably in /usr/bin. Could I encourage you to name it buildah-inet-helper or something less generic?

cc @lsm5, @jnovy, because you will need to deal with this in gating.yaml on all affected branches

Copy link
Member Author

Choose a reason for hiding this comment

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

The scripts will need to be told where it is regardless, since it won't be in ../bin relative to where the scripts end up packaged. At that point it's the packager's decision, as it is with the other test helpers.

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.

go code LGTM

@@ -133,6 +133,7 @@ export BUILDTAGS+=" btrfs_noversion exclude_graphdriver_btrfs"
%gobuild -o bin/imgtype ./tests/imgtype
%gobuild -o bin/copy ./tests/copy
%gobuild -o bin/tutorial ./tests/tutorial
%gobuild -o bin/inet ./tests/inet
Copy link
Member

Choose a reason for hiding this comment

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

this also needs to be added to the install section like bin/copy and then listed under %files tests

And since we had this discussion last week about podman-tests do we ship buildah-tests in RHEL as well? I really doubt we want to support these test helpers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, right. Adding.

return
}
// Start listening without specifying a port number.
ln, err := net.ListenTCP("tcp", &net.TCPAddr{})
Copy link
Member

Choose a reason for hiding this comment

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

I mean fair enough, it should not be a problem though as all test connect to localhost which generally should try both ::1 and 127.0.0.1 so I doubt it causes issues.

Use a listener helper to bind to an available-according-to-the-kernel
listening port and run a command with its stdio more or less tied to the
connection instead of trying to launch a git daemon directly using a
port number that we can only guess is available.

Signed-off-by: Nalin Dahyabhai <[email protected]>
This wrapper doesn't need to load anything from helpers.bash, because
the various .bats files already do so on their own.

Signed-off-by: Nalin Dahyabhai <[email protected]>
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 Oct 22, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99, nalind

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

@rhatdan
Copy link
Member

rhatdan commented Oct 22, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Oct 22, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit aeec2a1 into containers:main Oct 22, 2024
32 checks passed
@nalind nalind deleted the inet branch October 23, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved kind/flake Categorizes issue or PR as related to a flaky test. lgtm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants