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

Make the test signer easier to use in parallel tests #2373

Merged
merged 16 commits into from
Jun 11, 2024
Merged

Conversation

eljobe
Copy link
Member

@eljobe eljobe commented Jun 7, 2024

Previously, tests running in parallel would interfere with each other because the hard-coded signer port (1234) could only be bound in one of the two tests.

Now, the signer starts on an operating-system provided unused port.

eljobe added 5 commits June 6, 2024 16:50
This is especially useful in test code when you want to be able to
bring up local servers in your tests without conflicting with a test
that might be running in parallel.

Currently, the tests tagged challengetest fail on CI when they are run
in parallel with each other because only one test is able to bring up
a Signer on port 1234. The others silently fail to bring up a signer,
and the signer brought up by the first one may not still be around
when subsequently started parallel tests need one.
This makes the linter happy.
Previously, tests running in parallel would interfere with each other
because the hard-coded signer port (1234) could only be bound in one
of the two tests.

Now, the signer starts on an operating-system provided unused port.
@cla-bot cla-bot bot added the s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA. label Jun 7, 2024
eljobe added 2 commits June 7, 2024 16:06
These are fully expected and shouldn't be considered errors.
`!=` would have missed when those errors were wrapped.
@eljobe eljobe self-assigned this Jun 9, 2024
eljobe added 3 commits June 10, 2024 10:47
Both the httpServer struct's Addr and the SignerURL function can just use the address directly.
1. Close the listener which was created just to reseve the OS-provided port.
2. Comment on why the URL that clients use has to address "localhost".
@eljobe eljobe requested a review from gligneul June 10, 2024 14:44
eljobe added 2 commits June 10, 2024 18:43
This allows us to know the port we're listening on from the moment of
construction, but only start the server when Start is called.
@eljobe
Copy link
Member Author

eljobe commented Jun 10, 2024

Okay. This change now uses the new net.FreeTCPPortListener() function and uses the ServeTLS() API instead of the ListenAndServeTLS() API which allows us to provision the listener explicitly.

At this point, I'm "mildly" bothered that simply constructing the SigningServer also starts listening on the port. I think it's a bit counter-intuitive. If reviewers agree, I'll move the call to net.FreeTCPPortListener() to the Start() function and just initialize the http.Server with some placeholder Addr field that can be modified before calling ServeTLS() on the server.

gligneul
gligneul previously approved these changes Jun 10, 2024
Copy link
Contributor

@gligneul gligneul left a comment

Choose a reason for hiding this comment

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

Looks good!

At this point, I'm "mildly" bothered that simply constructing the SigningServer also starts listening on the port.

I don't mind it.

Copy link
Collaborator

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

A few comments, but this is going in the right direction. Labeled.

net/port_test.go Outdated Show resolved Hide resolved
net/port.go Outdated Show resolved Hide resolved
Specifically:
  1. Move the net package to util/testhelpers.
  2. Remove the concurrency test.
  3. Rename the SignerServer listner member.
@eljobe eljobe requested a review from gligneul June 11, 2024 10:42
@eljobe eljobe merged commit b7bccd8 into master Jun 11, 2024
11 checks passed
@eljobe eljobe deleted the fix-challenges branch June 11, 2024 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design-approved s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants