Skip to content

Commit

Permalink
Fix flaky test for reissuing certificate for local kube proxy. (#44066)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAM authored Jul 11, 2024
1 parent 0e45868 commit 0a02584
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/srv/alpnproxy/local_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,10 @@ func TestKubeMiddleware(t *testing.T) {
ServerName: "kube1",
},
}
// we set request context to a context that will expired immediately.
reqCtx, cancel := context.WithDeadline(context.Background(), time.Now())
defer cancel()
// we set request context to a context that is already canceled, so handler function will start reissuing
// certificate goroutine and then will exit immediately.
reqCtx, cancel := context.WithCancel(context.Background())
cancel()
req = req.WithContext(reqCtx)

km := NewKubeMiddleware(KubeMiddlewareConfig{
Expand All @@ -536,7 +537,7 @@ func TestKubeMiddleware(t *testing.T) {

// request timed out.
require.Equal(t, http.StatusInternalServerError, rw.Status())
require.Contains(t, rw.Buffer().String(), "context deadline exceeded")
require.Contains(t, rw.Buffer().String(), "context canceled")

// just let the reissuing goroutine some time to replace certs.
time.Sleep(10 * time.Millisecond)
Expand Down

0 comments on commit 0a02584

Please sign in to comment.