Skip to content

Commit f414b3d

Browse files
authored
Add node cache sync wait in TestPodController tests (kubernetes-sigs#1435)
* test: add node cache sync wait in TestPodController * re-run failed job
1 parent 52a7885 commit f414b3d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/kwok/controllers/node_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func TestNodeController(t *testing.T) {
100100
nodeCh := make(chan informer.Event[*corev1.Node], 1)
101101
nodesCli := clientset.CoreV1().Nodes()
102102
nodesInformer := informer.NewInformer[*corev1.Node, *corev1.NodeList](nodesCli)
103+
103104
err = nodesInformer.Watch(ctx, informer.Option{
104105
AnnotationSelector: "node=true",
105106
}, nodeCh)

pkg/kwok/controllers/pod_controller_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,22 @@ func TestPodController(t *testing.T) {
191191
t.Fatal(fmt.Errorf("failed to watch nodes: %w", err))
192192
}
193193

194+
// Wait for node cache to sync
195+
err = wait.Poll(ctx, func(ctx context.Context) (done bool, err error) {
196+
_, ok := nodeCache.Get("node0")
197+
if !ok {
198+
return false, nil
199+
}
200+
_, ok = nodeCache.Get("node1")
201+
if !ok {
202+
return false, nil
203+
}
204+
return true, nil
205+
}, wait.WithContinueOnError(5))
206+
if err != nil {
207+
t.Fatal(fmt.Errorf("failed to wait for node cache sync: %w", err))
208+
}
209+
194210
lc, _ := lifecycle.NewLifecycle(podStages)
195211
annotationSelector, _ := labels.Parse("fake=custom")
196212
pods, err := NewPodController(PodControllerConfig{

0 commit comments

Comments
 (0)