Skip to content

test(controller): poll for server readiness instead of sleeping - #2010

Draft
nikolauspschuetz wants to merge 1 commit into
bitnami:mainfrom
nikolauspschuetz:test-server-poll-not-sleep
Draft

test(controller): poll for server readiness instead of sleeping#2010
nikolauspschuetz wants to merge 1 commit into
bitnami:mainfrom
nikolauspschuetz:test-server-poll-not-sleep

Conversation

@nikolauspschuetz

Copy link
Copy Markdown

What

TestHttpCert slept a fixed time.Sleep(1 * time.Second) after starting the cert server, with a // TODO(mkm) find a better way, e.g. retries. That flakes if startup takes longer than a second under load, and wastes time when the server is ready sooner.

Replace it with a waitForServer helper that polls the listen address until it accepts a TCP connection (short per-dial timeout, 10s overall deadline). Dialing the socket rather than issuing an HTTP request is deliberate — the test populates the cert store after waiting, so an HTTP GET to /v1/cert.pem during the wait would exercise the handler before a cert is set.

Testing

go test ./pkg/controller/ -run TestHttpCert -count=5 passes (verified in a golang:1.26 container); the suite finishes faster than the previous fixed sleeps and no longer races startup.

TestHttpCert slept a fixed second after starting the cert server and
hoped it was ready (the code even carried a TODO to find a better way).
Under load that can flake if startup takes longer, and it wastes time
when the server is ready sooner. Dial the listen address until it
accepts a TCP connection instead, with a short timeout. TCP dialing
(rather than an HTTP request) avoids exercising the cert handler before
the test populates the cert store.

Signed-off-by: Nikolaus Schuetz <nikolauspschuetz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant