diff --git a/pkg/readiness/ready_tracker.go b/pkg/readiness/ready_tracker.go index dffec0903e7..6ff2a9bf035 100644 --- a/pkg/readiness/ready_tracker.go +++ b/pkg/readiness/ready_tracker.go @@ -89,6 +89,17 @@ type Tracker struct { trackListerPredicateOverride retryPredicate } +type WrapFakeClientWithMutex struct { + listMutex sync.Mutex + fakeLister Lister +} + +func (w *WrapFakeClientWithMutex) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error { + w.listMutex.Lock() + defer w.listMutex.Unlock() + return w.fakeLister.List(ctx, list, opts...) +} + // NewTracker creates a new Tracker and initializes the internal trackers. func NewTracker(lister Lister, mutationEnabled, externalDataEnabled, expansionEnabled bool) *Tracker { // TODO: Dereference crashOnFailureFetchingExpectations when we change crashOnFailureFetchingExpectations to a flag diff --git a/pkg/readiness/ready_tracker_unit_test.go b/pkg/readiness/ready_tracker_unit_test.go index ba5d039b941..74baa906704 100644 --- a/pkg/readiness/ready_tracker_unit_test.go +++ b/pkg/readiness/ready_tracker_unit_test.go @@ -211,7 +211,9 @@ func Test_ReadyTracker_TryCancelTemplate_No_Retries(t *testing.T) { // Verify that TryCancelTemplate must be called enough times to remove all retries before canceling a template. func Test_ReadyTracker_TryCancelTemplate_Retries(t *testing.T) { lister := fake.NewClientBuilder().WithScheme(mustInitializeScheme(runtime.NewScheme())).WithRuntimeObjects(convertedTemplate.DeepCopyObject()).Build() - rt := newTracker(lister, false, false, false, false, nil, func() objData { + wrapLister := WrapFakeClientWithMutex{fakeLister: lister} + + rt := newTracker(&wrapLister, false, false, false, false, nil, func() objData { return objData{retries: 2} })