Improve performance of TestForceApply unit test.

Change backOffPeriod from const to var, so that it can be set lower during unit test.
This commit is contained in:
Brian Pursley 2024-04-23 22:04:38 -04:00
parent 15ee05afd4
commit f011ed5ca5
2 changed files with 7 additions and 3 deletions

View File

@ -2087,6 +2087,9 @@ func TestForceApply(t *testing.T) {
"post": 1,
}
// Set the patch retry back off period to something low, so the test can run more quickly
patchRetryBackOffPeriod = 1 * time.Millisecond
for _, testingOpenAPISchema := range testingOpenAPISchemas {
for _, openAPIFeatureToggle := range applyFeatureToggles {

View File

@ -49,8 +49,6 @@ import (
const (
// maxPatchRetry is the maximum number of conflicts retry for during a patch operation before returning failure
maxPatchRetry = 5
// backOffPeriod is the period to back off when apply patch results in error.
backOffPeriod = 1 * time.Second
// how many times we can retry before back off
triesBeforeBackOff = 1
// groupVersionKindExtensionKey is the key used to lookup the
@ -59,6 +57,9 @@ const (
groupVersionKindExtensionKey = "x-kubernetes-group-version-kind"
)
// patchRetryBackOffPeriod is the period to back off when apply patch results in error.
var patchRetryBackOffPeriod = 1 * time.Second
var createPatchErrFormat = "creating patch with:\noriginal:\n%s\nmodified:\n%s\ncurrent:\n%s\nfor:"
// Patcher defines options to patch OpenAPI objects.
@ -363,7 +364,7 @@ func (p *Patcher) Patch(current runtime.Object, modified []byte, source, namespa
}
for i := 1; i <= p.Retries && apierrors.IsConflict(err); i++ {
if i > triesBeforeBackOff {
p.BackOff.Sleep(backOffPeriod)
p.BackOff.Sleep(patchRetryBackOffPeriod)
}
current, getErr = p.Helper.Get(namespace, name)
if getErr != nil {