Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ut in TestMultiClusterCache watch #3862

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions pkg/search/proxy/store/multi_cluster_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,29 +932,29 @@ func TestMultiClusterCache_Watch(t *testing.T) {
want want
}{
{
name: "resource version is empty",
name: "resource version is zero",
args: args{
options: &metainternalversion.ListOptions{
ResourceVersion: "",
ResourceVersion: "0",
},
},
want: want{
gets: sets.New[string]("pod11", "pod12", "pod13", "pod21", "pod22", "pod23"),
},
},
{
name: "resource version of cluster2 is empty",
name: "resource version of cluster2 is zero",
args: args{
options: &metainternalversion.ListOptions{
ResourceVersion: buildMultiClusterRV(cluster1.Name, "1002"),
ResourceVersion: buildMultiClusterRV(cluster1.Name, "1002", cluster2.Name, "0"),
},
},
want: want{
gets: sets.New[string]("pod13", "pod21", "pod22", "pod23"),
},
},
{
name: "resource versions are not empty",
name: "resource versions are not zero",
args: args{
options: &metainternalversion.ListOptions{
ResourceVersion: buildMultiClusterRV(cluster1.Name, "1002", cluster2.Name, "2002"),
Expand All @@ -968,15 +968,15 @@ func TestMultiClusterCache_Watch(t *testing.T) {

for _, tt := range tests {
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()
watcher, err := cache.Watch(ctx, podGVR, tt.args.options)
if err != nil {
t.Error(err)
return
}
defer watcher.Stop()
timeout := time.After(time.Second * 5)
waitCh := time.After(time.Second)

gets := sets.New[string]()
LOOP:
Expand All @@ -990,9 +990,8 @@ func TestMultiClusterCache_Watch(t *testing.T) {
if err == nil {
gets.Insert(accessor.GetName())
}
case <-timeout:
t.Error("timeout")
return
case <-waitCh:
break LOOP
}
}

Expand Down Expand Up @@ -1101,15 +1100,15 @@ func TestMultiClusterCache_Watch_Namespaced(t *testing.T) {
}
for _, tt := range tests {
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()
watcher, err := cache.Watch(ctx, podGVR, &metainternalversion.ListOptions{})
watcher, err := cache.Watch(ctx, podGVR, &metainternalversion.ListOptions{ResourceVersion: "0"})
if err != nil {
t.Error(err)
return
}
defer watcher.Stop()
timeout := time.After(time.Second * 5)
waitCh := time.After(time.Second)

gots := sets.New[string]()
LOOP:
Expand All @@ -1123,8 +1122,8 @@ func TestMultiClusterCache_Watch_Namespaced(t *testing.T) {
if err == nil {
gots.Insert(accessor.GetName())
}
case <-timeout:
t.Fatal("timeout")
case <-waitCh:
break LOOP
}
}

Expand Down