Skip to content

Commit e22a5a9

Browse files
committed
Introduce Thread Safety test for UpdateSubsSyncCounterStorage
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 e22a5a9

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Diff for: pkg/metrics/metrics_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package metrics
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+
)
11+
12+
func TestUpdateSubsSyncCounterStorageThreadSafety(t *testing.T) {
13+
sub := &operatorsv1alpha1.Subscription{
14+
ObjectMeta: metav1.ObjectMeta{
15+
Namespace: "foo",
16+
Name: "foo",
17+
},
18+
Spec: &operatorsv1alpha1.SubscriptionSpec{
19+
Channel: "foo",
20+
Package: "foo",
21+
InstallPlanApproval: "automatic",
22+
},
23+
Status: operatorsv1alpha1.SubscriptionStatus{
24+
InstalledCSV: "foo",
25+
},
26+
}
27+
for i := 0; i < 1000; i++ {
28+
go func(ii int) {
29+
sub.Spec.Channel = fmt.Sprintf("bar-%v", ii)
30+
UpdateSubsSyncCounterStorage(sub)
31+
}(i)
32+
}
33+
}

0 commit comments

Comments
 (0)