mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #71225 from jta/master
Fix duped watch in client-go/testing.
This commit is contained in:
commit
cab34050e7
@ -339,8 +339,10 @@ func (t *tracker) getWatches(gvr schema.GroupVersionResource, ns string) []*watc
|
|||||||
if w := t.watchers[gvr][ns]; w != nil {
|
if w := t.watchers[gvr][ns]; w != nil {
|
||||||
watches = append(watches, w...)
|
watches = append(watches, w...)
|
||||||
}
|
}
|
||||||
if w := t.watchers[gvr][""]; w != nil {
|
if ns != metav1.NamespaceAll {
|
||||||
watches = append(watches, w...)
|
if w := t.watchers[gvr][metav1.NamespaceAll]; w != nil {
|
||||||
|
watches = append(watches, w...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return watches
|
return watches
|
||||||
|
@ -131,26 +131,47 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
|
|||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
op watch.EventType
|
op watch.EventType
|
||||||
|
ns string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"foo",
|
"foo",
|
||||||
watch.Added,
|
watch.Added,
|
||||||
|
"test_namespace",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bar",
|
"bar",
|
||||||
watch.Added,
|
watch.Added,
|
||||||
|
"test_namespace",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"baz",
|
||||||
|
watch.Added,
|
||||||
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bar",
|
"bar",
|
||||||
watch.Modified,
|
watch.Modified,
|
||||||
|
"test_namespace",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"baz",
|
||||||
|
watch.Modified,
|
||||||
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"foo",
|
"foo",
|
||||||
watch.Deleted,
|
watch.Deleted,
|
||||||
|
"test_namespace",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bar",
|
"bar",
|
||||||
watch.Deleted,
|
watch.Deleted,
|
||||||
|
"test_namespace",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"baz",
|
||||||
|
watch.Deleted,
|
||||||
|
"",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,6 +190,7 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
|
|||||||
wg.Add(len(watchNamespaces))
|
wg.Add(len(watchNamespaces))
|
||||||
for idx, watchNamespace := range watchNamespaces {
|
for idx, watchNamespace := range watchNamespaces {
|
||||||
i := idx
|
i := idx
|
||||||
|
watchNamespace := watchNamespace
|
||||||
w, err := o.Watch(testResource, watchNamespace)
|
w, err := o.Watch(testResource, watchNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("test resource watch failed in %s: %v", watchNamespace, err)
|
t.Fatalf("test resource watch failed in %s: %v", watchNamespace, err)
|
||||||
@ -176,14 +198,17 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
|
|||||||
go func() {
|
go func() {
|
||||||
assert.NoError(t, err, "watch invocation failed")
|
assert.NoError(t, err, "watch invocation failed")
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
fmt.Printf("%#v %#v\n", c, i)
|
if watchNamespace == "" || c.ns == watchNamespace {
|
||||||
event := <-w.ResultChan()
|
fmt.Printf("%#v %#v\n", c, i)
|
||||||
accessor, err := meta.Accessor(event.Object)
|
event := <-w.ResultChan()
|
||||||
if err != nil {
|
accessor, err := meta.Accessor(event.Object)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, c.op, event.Type, "watch event mismatched")
|
||||||
|
assert.Equal(t, c.name, accessor.GetName(), "watched object mismatch")
|
||||||
|
assert.Equal(t, c.ns, accessor.GetNamespace(), "watched object mismatch")
|
||||||
}
|
}
|
||||||
assert.Equal(t, c.op, event.Type, "watch event mismatched")
|
|
||||||
assert.Equal(t, c.name, accessor.GetName(), "watched object mismatch")
|
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
@ -191,13 +216,13 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
|
|||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
switch c.op {
|
switch c.op {
|
||||||
case watch.Added:
|
case watch.Added:
|
||||||
obj := getArbitraryResource(testResource, c.name, "test_namespace")
|
obj := getArbitraryResource(testResource, c.name, c.ns)
|
||||||
o.Create(testResource, obj, "test_namespace")
|
o.Create(testResource, obj, c.ns)
|
||||||
case watch.Modified:
|
case watch.Modified:
|
||||||
obj := getArbitraryResource(testResource, c.name, "test_namespace")
|
obj := getArbitraryResource(testResource, c.name, c.ns)
|
||||||
o.Update(testResource, obj, "test_namespace")
|
o.Update(testResource, obj, c.ns)
|
||||||
case watch.Deleted:
|
case watch.Deleted:
|
||||||
o.Delete(testResource, "test_namespace", c.name)
|
o.Delete(testResource, c.ns, c.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
Loading…
Reference in New Issue
Block a user