Skip to content

Commit

Permalink
Introduce Thread Safety test for UpdateSubsSyncCounterStorage
Browse files Browse the repository at this point in the history
Introduces a test that ensure that the UpdateSubsSyncCounterStorage
function is thread safe and avoids concurrent map writes.

Signed-off-by: Alexander Greene <greene.al1991@gmail.com>
  • Loading branch information
awgreene committed Feb 1, 2023
1 parent 2a49a4d commit 1975e92
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/metrics/metrics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package metrics

import (
"fmt"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
)

func TestUpdateSubsSyncCounterStorageThreadSafety(t *testing.T) {
sub := &operatorsv1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Namespace: "foo",
Name: "foo",
},
Spec: &operatorsv1alpha1.SubscriptionSpec{
Channel: "foo",
Package: "foo",
InstallPlanApproval: "automatic",
},
Status: operatorsv1alpha1.SubscriptionStatus{
InstalledCSV: "foo",
},
}
for i := 0; i < 1000; i++ {
go func(ii int) {
sub.Spec.Channel = fmt.Sprintf("bar-%v", ii)
UpdateSubsSyncCounterStorage(sub)
}(i)
}
}

0 comments on commit 1975e92

Please sign in to comment.