Skip to content

Commit

Permalink
[v16] Fix flaky test for reissuing certificate for local kube proxy. (#…
Browse files Browse the repository at this point in the history
…44827)

* Fix flaky test again.

* Increase timeout to 5 seconds.
  • Loading branch information
AntonAM authored Jul 30, 2024
1 parent ca24d48 commit 65d0dde
Showing 1 changed file with 12 additions and 6 deletions.
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

0 comments on commit 65d0dde

Please sign in to comment.