Skip to content

Commit

Permalink
wrap fake client with mutex logic to resolve data race issues
Browse files Browse the repository at this point in the history
Signed-off-by: Avinash Patnala <[email protected]>
  • Loading branch information
Avinash Patnala committed Sep 19, 2024
1 parent 1be812c commit 2ac1e80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pkg/readiness/ready_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/readiness/ready_tracker_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
})

Expand Down

0 comments on commit 2ac1e80

Please sign in to comment.