avoid using t.Context inside t.Cleanup because it is already cancelled

This commit is contained in:
Ryan Richard
2025-07-30 15:22:20 -07:00
parent 1c1b3b7f2e
commit 3a02eec765
2 changed files with 5 additions and 3 deletions

View File

@@ -358,7 +358,7 @@ func run(ctx context.Context) error {
plog.Debug("controllers are ready")
listenConfig := net.ListenConfig{}
l, err := listenConfig.Listen(context.Background(), "tcp", ":8443")
l, err := listenConfig.Listen(ctx, "tcp", ":8443")
if err != nil {
return fmt.Errorf("cannot create listener: %w", err)
}

View File

@@ -1,4 +1,4 @@
// Copyright 2024 the Pinniped contributors. All Rights Reserved.
// Copyright 2024-2025 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package integration
@@ -701,7 +701,9 @@ func performKubectlApply(t *testing.T, resourceName string, yamlBytes []byte) (s
t.Cleanup(func() {
t.Helper()
require.NoError(t, exec.CommandContext(t.Context(), "kubectl", "delete", "--ignore-not-found", "-f", yamlFilepath).Run())
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
require.NoError(t, exec.CommandContext(ctx, "kubectl", "delete", "--ignore-not-found", "-f", yamlFilepath).Run())
})
return stdOut.String(), stdErr.String(), err