Skip to content

Commit e32582b

Browse files
Merge pull request #3378 from sebsoto/clientTimeoutTest
Add timeout to metrics query and cleanup job failure logs in e2e test
2 parents 6b6ff1b + 92ec5dc commit e32582b

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

test/e2e/metrics_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strconv"
1313
"strings"
1414
"testing"
15+
"time"
1516

1617
"github.com/stretchr/testify/assert"
1718
"github.com/stretchr/testify/require"
@@ -267,7 +268,7 @@ func makePrometheusQuery(address, query, token string) ([]Result, error) {
267268
// InsecureSkipVerify is required to avoid errors due to bad certificate
268269
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
269270
}
270-
client := &http.Client{Transport: tr}
271+
client := &http.Client{Transport: tr, Timeout: 15 * time.Second}
271272
resp, err := client.Do(req)
272273
if err != nil {
273274
return nil, fmt.Errorf("error making GET request: %w", err)

test/e2e/network_test.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -979,28 +979,11 @@ func (tc *testContext) waitUntilDeploymentScaled(name string) error {
979979
return false, nil
980980
})
981981
if err != nil {
982-
events, _ := tc.getPodEvents(name)
983-
return fmt.Errorf("error waiting for deployment %v to scale: %v: %w", deployment, events, err)
982+
return fmt.Errorf("error waiting for deployment %s to scale: %w", deployment.Name, err)
984983
}
985984
return nil
986985
}
987986

988-
// getPodEvents gets all events for any pod with the input in its name. Used for debugging purposes
989-
func (tc *testContext) getPodEvents(name string) ([]v1.Event, error) {
990-
eventList, err := tc.client.K8s.CoreV1().Events(tc.workloadNamespace).List(context.TODO(), metav1.ListOptions{
991-
FieldSelector: "involvedObject.kind=Pod"})
992-
if err != nil {
993-
return []v1.Event{}, err
994-
}
995-
var podEvents []v1.Event
996-
for _, event := range eventList.Items {
997-
if strings.Contains(event.InvolvedObject.Name, name) {
998-
podEvents = append(podEvents, event)
999-
}
1000-
}
1001-
return podEvents, nil
1002-
}
1003-
1004987
// createLinuxCurlerJob creates a linux job to curl a specific endpoint. curl must be present in the container image.
1005988
func (tc *testContext) createLinuxCurlerJob(jobSuffix, endpoint string, continuous bool) (*batchv1.Job, error) {
1006989
// Retries a failed curl attempt once to avoid flakes
@@ -1125,7 +1108,7 @@ func (tc *testContext) waitUntilJobSucceeds(name string) (string, error) {
11251108
for i := 0; i < 60; i++ {
11261109
job, err = tc.client.K8s.BatchV1().Jobs(tc.workloadNamespace).Get(context.TODO(), name, metav1.GetOptions{})
11271110
if err != nil {
1128-
return "", err
1111+
return "", fmt.Errorf("error getting job with name %s: %w", name, err)
11291112
}
11301113
if !slices.ContainsFunc(job.Status.Conditions, func(condition batchv1.JobCondition) bool {
11311114
return condition.Type == batchv1.JobComplete && condition.Status == v1.ConditionTrue
@@ -1143,17 +1126,15 @@ func (tc *testContext) waitUntilJobSucceeds(name string) (string, error) {
11431126
return condition.Type == batchv1.JobSuccessCriteriaMet && condition.Status == v1.ConditionTrue
11441127
}) {
11451128
// Job did not succeed, return error
1146-
events, _ := tc.getPodEvents(name)
1147-
return logs, fmt.Errorf("job %v failed: %v", job, events)
1129+
return logs, fmt.Errorf("job %s failed", name)
11481130
}
11491131
return logs, nil
11501132
}
11511133
_, err = tc.gatherPodLogs(labelSelector, true)
11521134
if err != nil {
11531135
log.Printf("Unable to get logs associated with pod %s: %v", labelSelector, err)
11541136
}
1155-
events, _ := tc.getPodEvents(name)
1156-
return "", fmt.Errorf("job %v timed out: %v", job, events)
1137+
return "", fmt.Errorf("job %s timed out", name)
11571138
}
11581139

11591140
// gatherPodLogs writes the logs associated with the label selector of a given pod job or deployment to the Artifacts

0 commit comments

Comments
 (0)