Skip to content

test: fix flaky allocation metrics test server startup#4445

Merged
markmandel merged 3 commits intoagones-dev:mainfrom
srpvpn:fix-issue-4444-allocation-metrics
Feb 13, 2026
Merged

test: fix flaky allocation metrics test server startup#4445
markmandel merged 3 commits intoagones-dev:mainfrom
srpvpn:fix-issue-4444-allocation-metrics

Conversation

@srpvpn
Copy link
Copy Markdown
Contributor

@srpvpn srpvpn commented Feb 11, 2026

Title
test: fix flaky TestAllocationMetrics port conflict and startup race

Changes:

  • Removed hardcoded metrics port (3001) from the test path.
  • Added dynamic test server bootstrap using a pre-bound ephemeral listener (127.0.0.1:0).
  • Replaced fixed time.Sleep(300ms) with readiness polling against the metrics endpoint.
  • Added TestStartMetricsServer to validate server bootstrap helper behavior.

Fix #4444

@google-cla
Copy link
Copy Markdown

google-cla bot commented Feb 11, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Collaborator

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

Thanks for tacking this!

_ = server.Run(ctxHTTP, 0)
}()
time.Sleep(300 * time.Millisecond)
err = wait.PollUntilContextTimeout(context.Background(), 10*time.Millisecond, 5*time.Second, true, func(_ context.Context) (bool, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We're moving to using https://pkg.go.dev/github.com/stretchr/testify/require#EventuallyWithT for polling tests -- it gives a much better developer surface and also error messages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I did it.

@markmandel
Copy link
Copy Markdown
Collaborator

/gcbrun

@agones-bot
Copy link
Copy Markdown
Collaborator

Build Succeeded 🥳

Build Id: 0cd6d6ce-0486-402b-9eee-c8e4d73d0783

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

git fetch https://github.com/googleforgames/agones.git pull/4445/head:pr_4445 && git checkout pr_4445
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.56.0-dev-0350016

Copy link
Copy Markdown
Collaborator

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this! Almost there.


metricsURL := startMetricsServerForTest(t, server)

err := wait.PollUntilContextTimeout(context.Background(), 10*time.Millisecond, time.Second, true, func(_ context.Context) (bool, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same thing as well here please - EventuallyWithT.

Also means that if assert.NoError(t, resp.Body.Close()) fails for some reason it will get reported appropriately.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, thanks, I did that too

@markmandel
Copy link
Copy Markdown
Collaborator

/gcbrun

@agones-bot
Copy link
Copy Markdown
Collaborator

Build Succeeded 🥳

Build Id: 770e853b-be34-49ae-930f-42b0cde024bc

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

git fetch https://github.com/googleforgames/agones.git pull/4445/head:pr_4445 && git checkout pr_4445
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.56.0-dev-a0ef9eb

Copy link
Copy Markdown
Collaborator

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

Thanks!

@markmandel markmandel enabled auto-merge (squash) February 13, 2026 21:18
@markmandel
Copy link
Copy Markdown
Collaborator

/gcbrun

@agones-bot
Copy link
Copy Markdown
Collaborator

Build Succeeded 🥳

Build Id: 49acc863-e448-4988-9ee8-17bff6ffca22

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

git fetch https://github.com/googleforgames/agones.git pull/4445/head:pr_4445 && git checkout pr_4445
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.56.0-dev-e0372ce

@markmandel markmandel merged commit b9bbac2 into agones-dev:main Feb 13, 2026
5 checks passed
mnthe pushed a commit to mnthe/agones that referenced this pull request Mar 23, 2026
* test: fix flaky allocation metrics test server startup

* test: use EventuallyWithT for metrics readiness poll

* test: use EventuallyWithT in start metrics server test

---------

Co-authored-by: srpvpn <srpvpn@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky Test: TestAllocationMetrics fails with "address already in use" on port 3001

3 participants