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

[v16] Fix flaky test for reissuing certificate for local kube proxy. #44827

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/srv/alpnproxy/local_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,18 @@ func TestKubeMiddleware(t *testing.T) {
err := km.CheckAndSetDefaults()
require.NoError(t, err)

rw := responsewriters.NewMemoryResponseWriter()
// HandleRequest will reissue certificate if needed.
km.HandleRequest(rw, req)

// request timed out.
require.Equal(t, http.StatusInternalServerError, rw.Status())
var rw *responsewriters.MemoryResponseWriter
// We use `require.Eventually` to avoid a very rare test flakiness case when reissue goroutine manages to
// successfully finish before the parent goroutine has a chance to check the context (and see that it's expired).
require.Eventually(t, func() bool {
rw = responsewriters.NewMemoryResponseWriter()
// HandleRequest will reissue certificate if needed.
km.HandleRequest(rw, req)

// request timed out.
return rw.Status() == http.StatusInternalServerError

}, 5*time.Second, 100*time.Millisecond)
require.Contains(t, rw.Buffer().String(), "context canceled")

// just let the reissuing goroutine some time to replace certs.
Expand Down
Loading