-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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: use a queue of open ports for tests #14893
Conversation
This reverts commit d877dfe.
After some experimentation there are a couple of ways we can improve this:
Let's give the first option a go and see how that goes. |
The solution here is pretty simple, just a buffered channel. Also there's a mutex that only allows to run a single network at a time, so that means port collision happens during the same execution and not between multiple executions of Some tests use I've tried removing the mutex lock, but it looks like it can cause some issues with almost-flaky tests (usually timing issues). Would be useful to investigate if we can run multiple tests/networks at the same time to improve our CI times (maybe add some limit in the amount to avoid saturating resources). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK.
We should remove network.new. This will happen with the integration and e2e framework work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UtAck. Nice solution
Co-authored-by: Marko <[email protected]> (cherry picked from commit 5e57be0) # Conflicts: # testutil/network/network.go # testutil/network/util.go # x/genutil/client/cli/init_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't how I imagined the solution to look like honestly. IMO FreeTCPAddr
should be the thing that is protected against collisions.
@alexanderbez wdym? That we should move the port pool inside of FreeTCPAddr? |
|
Hey all. I just wanted to point out something non-obvious about the way When go tests are invoked with I'd encourage you to test this out yourself to see what I mean. For example, add a For this reason I don't think the current solution solves the issue, as the As a workaround for these issues, we ended up adding a file-level lock around |
Intersting point @prettymuchbryce you're right. I didn't realize Go handles tests this way. Indeed this makes both my suggestion to the PR and the original PR itself useless. Is there a cleaner way to guarantee package-level synchronization across tests? |
I think this would be a good solution, I'll close the backport to v0.47 for now and reopen #14837. I can implement it although would be cool to see your solution @prettymuchbryce
I don't have an answer for this, will do some research. The obvious answer right now is the filesystem, either directly or through a db. |
Our solution uses file-level locks. This solution works, but the disadvantage is that it could potentially leave temporary files on the system if the process is killed or crashes during the test. import (
"github.com/gofrs/flock"
)
var fileLock = flock.New("/tmp/test-cosmos-network.lock")
func New(t *testing.T, configs ...network.Config) *network.Network {
err := fileLock.Lock()
require.NoError(t, err)
defer func() {
err := fileLock.Unlock()
require.NoError(t, err)
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
for range c {
fileLock.Close()
return
}
}()
cfg := network.DefaultConfig(app.NewTestNetworkFixture)
net, err := network.New(t, t.TempDir(), cfg)
if err != nil {
panic(err)
}
t.Cleanup(net.Cleanup)
return net
} This is why I suggested the approach of listening on port |
Why have you not opted for the zero-port allocation yourself? |
I've explored passing the
So it's doable, but a bit cumbersome. Would it make sense to go after this? |
Co-authored-by: Marko <[email protected]>
Description
In this PR we first store a list of 200 free ports and then use them one by one.
Closes: #14837
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change