test(controller): poll for server readiness instead of sleeping - #2010
Draft
nikolauspschuetz wants to merge 1 commit into
Draft
test(controller): poll for server readiness instead of sleeping#2010nikolauspschuetz wants to merge 1 commit into
nikolauspschuetz wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
TestHttpCertslept a fixedtime.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
waitForServerhelper 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.pemduring the wait would exercise the handler before a cert is set.Testing
go test ./pkg/controller/ -run TestHttpCert -count=5passes (verified in agolang:1.26container); the suite finishes faster than the previous fixed sleeps and no longer races startup.