UPSTREAM: 73516: Wait for post-hooks to run before checking the healthz output
@@ -57,7 +57,9 @@ func TestNewWithDelegate(t *testing.T) {
w.WriteHeader(http.StatusForbidden)
})
+ delegatePostStartHookChan := make(chan struct{})
delegateServer.AddPostStartHook("delegate-post-start-hook", func(context PostStartHookContext) error {
+ defer close(delegatePostStartHookChan)
return nil
})
@@ -84,7 +86,9 @@ func TestNewWithDelegate(t *testing.T) {
w.WriteHeader(http.StatusUnauthorized)
})
+ wrappingPostStartHookChan := make(chan struct{})
wrappingServer.AddPostStartHook("wrapping-post-start-hook", func(context PostStartHookContext) error {
+ defer close(wrappingPostStartHookChan)
return nil
})
@@ -96,6 +100,10 @@ func TestNewWithDelegate(t *testing.T) {
server := httptest.NewServer(wrappingServer.Handler)
defer server.Close()
+ // Wait for the hooks to finish before checking the response
+ <-delegatePostStartHookChan
+ <-wrappingPostStartHookChan
+
checkPath(server.URL, http.StatusOK, `{
"paths": [
"/apis",
