mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-09 10:59:57 +00:00
Use RaceFreeFakeWatcher in ObjectTracker
The FakeWatcher allows sends on the result channel after it's closed, for example calling Stop() then Add() will panic. RaceFreeFakeWatcher checks whether the watcher is stopped before attempting to send. It also panics instead of blocking when the result channel is full. Kubernetes-commit: b84ad8828b6ffe0dd289f69e395968eabb9fbeaa
This commit is contained in:
committed by
Kubernetes Publisher
parent
d74b6802c2
commit
949db79a1d
@@ -190,3 +190,34 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestWatchAddAfterStop(t *testing.T) {
|
||||
testResource := schema.GroupVersionResource{Group: "", Version: "test_version", Resource: "test_kind"}
|
||||
testObj := getArbitraryResource(testResource, "test_name", "test_namespace")
|
||||
accessor, err := meta.Accessor(testObj)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
ns := accessor.GetNamespace()
|
||||
scheme := runtime.NewScheme()
|
||||
codecs := serializer.NewCodecFactory(scheme)
|
||||
o := NewObjectTracker(scheme, codecs.UniversalDecoder())
|
||||
watch, err := o.Watch(testResource, ns)
|
||||
if err != nil {
|
||||
t.Errorf("watch creation failed: %v", err)
|
||||
}
|
||||
|
||||
// When the watch is stopped it should ignore later events without panicking.
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Errorf("Watch panicked when it should have ignored create after stop: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
watch.Stop()
|
||||
err = o.Create(testResource, testObj, ns)
|
||||
if err != nil {
|
||||
t.Errorf("test resource creation failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user