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.
21
"istio.io/istio/pilot/pkg/config/memory"
22
"istio.io/istio/pilot/pkg/model"
23
"istio.io/istio/pilot/test/mock"
24
"istio.io/istio/pkg/config"
25
"istio.io/istio/pkg/config/schema/collections"
28
func TestMonitorLifecycle(t *testing.T) {
29
// Regression test to ensure no race conditions during monitor shutdown
30
store := memory.Make(collections.Mocks)
31
m := memory.NewMonitor(store)
32
stop := make(chan struct{})
34
m.ScheduleProcessEvent(memory.ConfigEvent{})
36
m.ScheduleProcessEvent(memory.ConfigEvent{})
39
func TestEventConsistency(t *testing.T) {
40
store := memory.Make(collections.Mocks)
41
controller := memory.NewController(store)
43
testConfig := mock.Make(TestNamespace, 0)
44
var testEvent model.Event
46
done := make(chan bool)
50
controller.RegisterEventHandler(collections.Mock.GroupVersionKind(), func(_, config config.Config, event model.Event) {
55
if event != testEvent {
56
t.Errorf("desired %v, but %v", testEvent, event)
58
if !mock.Compare(tc, config) {
59
t.Errorf("desired %v, but %v", tc, config)
64
stop := make(chan struct{})
65
go controller.Run(stop)
68
testEvent = model.EventAdd
71
if rev, err = controller.Create(testConfig); err != nil {
77
testConfig.ResourceVersion = rev
83
testEvent = model.EventUpdate
84
if _, err := controller.Update(testConfig); err != nil {
91
testEvent = model.EventDelete
92
if err := controller.Delete(collections.Mock.GroupVersionKind(), testConfig.Name, TestNamespace, nil); err != nil {