Merge pull request #118744 from mimowo/job-it-tests-small-default-backoff

Set small DefaultJobPodFailureBackOff in Job integration tests
This commit is contained in:
Kubernetes Prow Robot 2023-06-19 08:50:22 -07:00 committed by GitHub
commit 162034db85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,6 +66,7 @@ import (
)
const waitInterval = time.Second
const fastPodFailureBackoff = 100 * time.Millisecond
type metricLabelsWithValue struct {
Labels []string
@ -467,6 +468,7 @@ func TestJobPodFailurePolicyWithFailedPodDeletedDuringControllerRestart(t *testi
// TestJobPodFailurePolicy tests handling of pod failures with respect to the
// configured pod failure policy rules
func TestJobPodFailurePolicy(t *testing.T) {
t.Cleanup(setDurationDuringTest(&jobcontroller.DefaultJobPodFailureBackOff, fastPodFailureBackoff))
job := batchv1.Job{
Spec: batchv1.JobSpec{
Template: v1.PodTemplateSpec{
@ -689,6 +691,7 @@ func TestJobPodFailurePolicy(t *testing.T) {
// recreates the Job controller at some points to make sure a new controller
// is able to pickup.
func TestNonParallelJob(t *testing.T) {
t.Cleanup(setDurationDuringTest(&jobcontroller.DefaultJobPodFailureBackOff, fastPodFailureBackoff))
closeFn, restConfig, clientSet, ns := setup(t, "simple")
defer closeFn()
ctx, cancel := startJobControllerAndWaitForCaches(restConfig)
@ -737,6 +740,7 @@ func TestNonParallelJob(t *testing.T) {
}
func TestParallelJob(t *testing.T) {
t.Cleanup(setDurationDuringTest(&jobcontroller.DefaultJobPodFailureBackOff, fastPodFailureBackoff))
cases := map[string]struct {
enableReadyPods bool
}{
@ -893,6 +897,7 @@ func TestParallelJobWithCompletions(t *testing.T) {
// number of pods.
t.Cleanup(setDuringTest(&jobcontroller.MaxUncountedPods, 10))
t.Cleanup(setDuringTest(&jobcontroller.MaxPodCreateDeletePerSync, 10))
t.Cleanup(setDurationDuringTest(&jobcontroller.DefaultJobPodFailureBackOff, fastPodFailureBackoff))
cases := map[string]struct {
enableReadyPods bool
}{
@ -977,6 +982,7 @@ func TestParallelJobWithCompletions(t *testing.T) {
}
func TestIndexedJob(t *testing.T) {
t.Cleanup(setDurationDuringTest(&jobcontroller.DefaultJobPodFailureBackOff, fastPodFailureBackoff))
closeFn, restConfig, clientSet, ns := setup(t, "indexed")
defer closeFn()
ctx, cancel := startJobControllerAndWaitForCaches(restConfig)
@ -1378,11 +1384,7 @@ func TestFinalizersClearedWhenBackoffLimitExceeded(t *testing.T) {
}
func TestJobPodsCreatedWithExponentialBackoff(t *testing.T) {
// overwrite the default value for faster testing
oldBackoff := jobcontroller.DefaultJobPodFailureBackOff
defer func() { jobcontroller.DefaultJobPodFailureBackOff = oldBackoff }()
jobcontroller.DefaultJobPodFailureBackOff = 2 * time.Second
t.Cleanup(setDurationDuringTest(&jobcontroller.DefaultJobPodFailureBackOff, 2*time.Second))
closeFn, restConfig, clientSet, ns := setup(t, "simple")
defer closeFn()
ctx, cancel := startJobControllerAndWaitForCaches(restConfig)
@ -2141,6 +2143,14 @@ func setDuringTest(val *int, newVal int) func() {
}
}
func setDurationDuringTest(val *time.Duration, newVal time.Duration) func() {
origVal := *val
*val = newVal
return func() {
*val = origVal
}
}
func updateJob(ctx context.Context, jobClient typedv1.JobInterface, jobName string, updateFunc func(*batchv1.Job)) (*batchv1.Job, error) {
var job *batchv1.Job
err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {