fix ut in TestMultiClusterCache watch
Signed-off-by: yingjinhui <yingjinhui@didiglobal.com>
This commit is contained in:
parent
2526de856e
commit
fda27d96bb
|
@ -932,10 +932,10 @@ func TestMultiClusterCache_Watch(t *testing.T) {
|
||||||
want want
|
want want
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "resource version is empty",
|
name: "resource version is zero",
|
||||||
args: args{
|
args: args{
|
||||||
options: &metainternalversion.ListOptions{
|
options: &metainternalversion.ListOptions{
|
||||||
ResourceVersion: "",
|
ResourceVersion: "0",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
|
@ -943,10 +943,10 @@ func TestMultiClusterCache_Watch(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "resource version of cluster2 is empty",
|
name: "resource version of cluster2 is zero",
|
||||||
args: args{
|
args: args{
|
||||||
options: &metainternalversion.ListOptions{
|
options: &metainternalversion.ListOptions{
|
||||||
ResourceVersion: buildMultiClusterRV(cluster1.Name, "1002"),
|
ResourceVersion: buildMultiClusterRV(cluster1.Name, "1002", cluster2.Name, "0"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
|
@ -954,7 +954,7 @@ func TestMultiClusterCache_Watch(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "resource versions are not empty",
|
name: "resource versions are not zero",
|
||||||
args: args{
|
args: args{
|
||||||
options: &metainternalversion.ListOptions{
|
options: &metainternalversion.ListOptions{
|
||||||
ResourceVersion: buildMultiClusterRV(cluster1.Name, "1002", cluster2.Name, "2002"),
|
ResourceVersion: buildMultiClusterRV(cluster1.Name, "1002", cluster2.Name, "2002"),
|
||||||
|
@ -968,7 +968,7 @@ func TestMultiClusterCache_Watch(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(request.WithNamespace(context.TODO(), metav1.NamespaceDefault), time.Second)
|
ctx, cancel := context.WithCancel(request.WithNamespace(context.TODO(), metav1.NamespaceDefault))
|
||||||
defer cancel()
|
defer cancel()
|
||||||
watcher, err := cache.Watch(ctx, podGVR, tt.args.options)
|
watcher, err := cache.Watch(ctx, podGVR, tt.args.options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -976,7 +976,7 @@ func TestMultiClusterCache_Watch(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer watcher.Stop()
|
defer watcher.Stop()
|
||||||
timeout := time.After(time.Second * 5)
|
waitCh := time.After(time.Second)
|
||||||
|
|
||||||
gets := sets.New[string]()
|
gets := sets.New[string]()
|
||||||
LOOP:
|
LOOP:
|
||||||
|
@ -990,9 +990,8 @@ func TestMultiClusterCache_Watch(t *testing.T) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
gets.Insert(accessor.GetName())
|
gets.Insert(accessor.GetName())
|
||||||
}
|
}
|
||||||
case <-timeout:
|
case <-waitCh:
|
||||||
t.Error("timeout")
|
break LOOP
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1101,15 +1100,15 @@ func TestMultiClusterCache_Watch_Namespaced(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(request.WithNamespace(context.TODO(), tt.args.ns), time.Second)
|
ctx, cancel := context.WithCancel(request.WithNamespace(context.TODO(), tt.args.ns))
|
||||||
defer cancel()
|
defer cancel()
|
||||||
watcher, err := cache.Watch(ctx, podGVR, &metainternalversion.ListOptions{})
|
watcher, err := cache.Watch(ctx, podGVR, &metainternalversion.ListOptions{ResourceVersion: "0"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer watcher.Stop()
|
defer watcher.Stop()
|
||||||
timeout := time.After(time.Second * 5)
|
waitCh := time.After(time.Second)
|
||||||
|
|
||||||
gots := sets.New[string]()
|
gots := sets.New[string]()
|
||||||
LOOP:
|
LOOP:
|
||||||
|
@ -1123,8 +1122,8 @@ func TestMultiClusterCache_Watch_Namespaced(t *testing.T) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
gots.Insert(accessor.GetName())
|
gots.Insert(accessor.GetName())
|
||||||
}
|
}
|
||||||
case <-timeout:
|
case <-waitCh:
|
||||||
t.Fatal("timeout")
|
break LOOP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue