1
// Copyright Istio Authors
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
22
. "github.com/onsi/gomega"
23
"k8s.io/apimachinery/pkg/runtime/schema"
25
"istio.io/api/meta/v1alpha1"
26
"istio.io/istio/pkg/config"
29
func TestResourceLock_Lock(t *testing.T) {
30
g := NewGomegaWithT(t)
32
GroupVersionResource: schema.GroupVersionResource{
41
GroupVersionResource: schema.GroupVersionResource{
50
x := make(chan struct{})
51
y := make(chan struct{})
52
mgr := NewManager(nil)
53
fakefunc := func(status *v1alpha1.IstioStatus, context any) *v1alpha1.IstioStatus {
55
atomic.AddInt32(&runCount, 1)
59
c1 := mgr.CreateIstioStatusController(fakefunc)
60
c2 := mgr.CreateIstioStatusController(fakefunc)
61
workers := NewWorkerPool(func(_ *config.Config, _ any) {
62
}, func(resource Resource) *config.Config {
63
return &config.Config{
64
Meta: config.Meta{Generation: 11},
67
ctx, cancel := context.WithCancel(context.Background())
69
workers.Push(r1, c1, nil)
70
workers.Push(r1, c2, nil)
71
workers.Push(r1, c1, nil)
75
workers.Push(r1, c1, nil)
76
workers.Push(r1a, c1, nil)
85
result := atomic.LoadInt32(&runCount)
86
g.Expect(result).To(Equal(int32(3)))