mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #14616 from mvdan/controller-framework-flake
Controller framework test flake fix
This commit is contained in:
commit
22fa2db39a
@ -133,7 +133,7 @@ func ExampleInformer() {
|
|||||||
time.Millisecond*100,
|
time.Millisecond*100,
|
||||||
framework.ResourceEventHandlerFuncs{
|
framework.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(obj interface{}) {
|
AddFunc: func(obj interface{}) {
|
||||||
source.Delete(obj.(runtime.Object))
|
source.DeleteDropWatch(obj.(runtime.Object))
|
||||||
},
|
},
|
||||||
DeleteFunc: func(obj interface{}) {
|
DeleteFunc: func(obj interface{}) {
|
||||||
key, err := framework.DeletionHandlingMetaNamespaceKeyFunc(obj)
|
key, err := framework.DeletionHandlingMetaNamespaceKeyFunc(obj)
|
||||||
@ -327,7 +327,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
if !allowedTransitions[pair{from, to}] {
|
if !allowedTransitions[pair{from, to}] {
|
||||||
t.Errorf("observed transition %q -> %q for %v", from, to, n.Name)
|
t.Errorf("observed transition %q -> %q for %v", from, to, n.Name)
|
||||||
}
|
}
|
||||||
source.Delete(n)
|
source.DeleteDropWatch(n)
|
||||||
},
|
},
|
||||||
DeleteFunc: func(obj interface{}) {
|
DeleteFunc: func(obj interface{}) {
|
||||||
testDoneWG.Done()
|
testDoneWG.Done()
|
||||||
@ -384,7 +384,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
go func(name string, f func(string)) {
|
go func(name string, f func(string)) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
f(name)
|
f(name)
|
||||||
}(fmt.Sprintf("%v-%v", i, j), f)
|
}(fmt.Sprintf("%d-%d", i, j), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -37,7 +37,7 @@ func NewFakeControllerSource() *FakeControllerSource {
|
|||||||
|
|
||||||
// FakeControllerSource implements listing/watching for testing.
|
// FakeControllerSource implements listing/watching for testing.
|
||||||
type FakeControllerSource struct {
|
type FakeControllerSource struct {
|
||||||
lock sync.RWMutex
|
sync.RWMutex
|
||||||
items map[nnu]runtime.Object
|
items map[nnu]runtime.Object
|
||||||
changes []watch.Event // one change per resourceVersion
|
changes []watch.Event // one change per resourceVersion
|
||||||
broadcaster *watch.Broadcaster
|
broadcaster *watch.Broadcaster
|
||||||
@ -95,8 +95,8 @@ func (f *FakeControllerSource) key(meta *api.ObjectMeta) nnu {
|
|||||||
// Change records the given event (setting the object's resource version) and
|
// Change records the given event (setting the object's resource version) and
|
||||||
// sends a watch event with the specified probability.
|
// sends a watch event with the specified probability.
|
||||||
func (f *FakeControllerSource) Change(e watch.Event, watchProbability float64) {
|
func (f *FakeControllerSource) Change(e watch.Event, watchProbability float64) {
|
||||||
f.lock.Lock()
|
f.Lock()
|
||||||
defer f.lock.Unlock()
|
defer f.Unlock()
|
||||||
|
|
||||||
objMeta, err := api.ObjectMetaFor(e.Object)
|
objMeta, err := api.ObjectMetaFor(e.Object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -121,8 +121,8 @@ func (f *FakeControllerSource) Change(e watch.Event, watchProbability float64) {
|
|||||||
|
|
||||||
// List returns a list object, with its resource version set.
|
// List returns a list object, with its resource version set.
|
||||||
func (f *FakeControllerSource) List() (runtime.Object, error) {
|
func (f *FakeControllerSource) List() (runtime.Object, error) {
|
||||||
f.lock.RLock()
|
f.RLock()
|
||||||
defer f.lock.RUnlock()
|
defer f.RUnlock()
|
||||||
list := make([]runtime.Object, 0, len(f.items))
|
list := make([]runtime.Object, 0, len(f.items))
|
||||||
for _, obj := range f.items {
|
for _, obj := range f.items {
|
||||||
// Must make a copy to allow clients to modify the object.
|
// Must make a copy to allow clients to modify the object.
|
||||||
@ -151,8 +151,8 @@ func (f *FakeControllerSource) List() (runtime.Object, error) {
|
|||||||
// Watch returns a watch, which will be pre-populated with all changes
|
// Watch returns a watch, which will be pre-populated with all changes
|
||||||
// after resourceVersion.
|
// after resourceVersion.
|
||||||
func (f *FakeControllerSource) Watch(resourceVersion string) (watch.Interface, error) {
|
func (f *FakeControllerSource) Watch(resourceVersion string) (watch.Interface, error) {
|
||||||
f.lock.RLock()
|
f.RLock()
|
||||||
defer f.lock.RUnlock()
|
defer f.RUnlock()
|
||||||
rc, err := strconv.Atoi(resourceVersion)
|
rc, err := strconv.Atoi(resourceVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user