-
Notifications
You must be signed in to change notification settings - Fork 68
🐛 Add checks to catch race-driven panics in metrics endpoint e2e #1795
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,10 +15,13 @@ package e2e | |
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "fmt" | ||
| "io" | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
|
|
@@ -156,11 +159,43 @@ func (c *MetricsTestConfig) validate(token string) { | |
| require.Contains(c.t, string(output), "200 OK", "Metrics endpoint did not return 200 OK") | ||
| } | ||
|
|
||
| // cleanup created resources | ||
| // cleanup removes the created resources. Uses a context with timeout to prevent hangs. | ||
| func (c *MetricsTestConfig) cleanup() { | ||
| c.t.Log("Cleaning up resources") | ||
| _ = exec.Command(c.client, "delete", "clusterrolebinding", c.clusterBinding, "--ignore-not-found=true").Run() | ||
| _ = exec.Command(c.client, "delete", "pod", c.curlPodName, "-n", c.namespace, "--ignore-not-found=true").Run() | ||
| _ = exec.Command(c.client, "delete", "clusterrolebinding", c.clusterBinding, "--ignore-not-found=true", "--force").Run() | ||
| _ = exec.Command(c.client, "delete", "pod", c.curlPodName, "-n", c.namespace, "--ignore-not-found=true", "--force").Run() | ||
|
|
||
| // Create a context with a 60-second timeout. | ||
| ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) | ||
| defer cancel() | ||
|
|
||
| // Wait for the ClusterRoleBinding to be deleted. | ||
| if err := waitForDeletion(ctx, c.client, "clusterrolebinding", c.clusterBinding); err != nil { | ||
| c.t.Logf("Error waiting for clusterrolebinding deletion: %v", err) | ||
| } else { | ||
| c.t.Log("ClusterRoleBinding deleted") | ||
| } | ||
|
|
||
| // Wait for the Pod to be deleted. | ||
| if err := waitForDeletion(ctx, c.client, "pod", c.curlPodName, "-n", c.namespace); err != nil { | ||
| c.t.Logf("Error waiting for pod deletion: %v", err) | ||
| } else { | ||
| c.t.Log("Pod deleted") | ||
| } | ||
|
Comment on lines
+172
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need to even wait for these to be deleted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, good point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be clear: I have a pretty quick test ((takes about ~50m) -- run e2e 10 times. This test always fails on my local box when run on |
||
| } | ||
|
|
||
| // waitForDeletion uses "kubectl wait" to block until the specified resource is deleted | ||
| // or until the 60-second timeout is reached. | ||
| func waitForDeletion(ctx context.Context, client, resourceType, resourceName string, extraArgs ...string) error { | ||
| args := []string{"wait", "--for=delete", resourceType, resourceName} | ||
| args = append(args, extraArgs...) | ||
| args = append(args, "--timeout=60s") | ||
| cmd := exec.CommandContext(ctx, client, args...) | ||
| output, err := cmd.CombinedOutput() | ||
| if err != nil { | ||
| return fmt.Errorf("error waiting for deletion of %s %s: %v, output: %s", resourceType, resourceName, err, string(output)) | ||
| } | ||
| return nil | ||
| } | ||
bentito marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // getComponentNamespace returns the namespace where operator-controller or catalogd is running | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.