Skip to content

Commit 84ab8d2

Browse files
authored
Thread Safety test for UpdateSubsSyncCounterStorage (#2918)
Introduces a test that ensure that the UpdateSubsSyncCounterStorage function is thread safe and avoids concurrent map writes. Signed-off-by: Alexander Greene <[email protected]>
1 parent e29776d commit 84ab8d2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pkg/metrics/metrics_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package metrics_test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
9+
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
10+
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
11+
)
12+
13+
func TestUpdateSubsSyncCounterStorageThreadSafety(t *testing.T) {
14+
for i := 0; i < 1000; i++ {
15+
go func(ii int) {
16+
sub := &operatorsv1alpha1.Subscription{
17+
ObjectMeta: metav1.ObjectMeta{
18+
Namespace: "foo",
19+
Name: "foo",
20+
},
21+
Spec: &operatorsv1alpha1.SubscriptionSpec{
22+
Channel: "foo",
23+
Package: "foo",
24+
InstallPlanApproval: "automatic",
25+
},
26+
Status: operatorsv1alpha1.SubscriptionStatus{
27+
InstalledCSV: "foo",
28+
},
29+
}
30+
sub.Spec.Channel = fmt.Sprintf("bar-%v", ii)
31+
metrics.UpdateSubsSyncCounterStorage(sub)
32+
}(i)
33+
}
34+
}

0 commit comments

Comments
 (0)