@@ -26,8 +26,10 @@ import (
2626 "github.com/pkg/errors"
2727 apierrors "k8s.io/apimachinery/pkg/api/errors"
2828 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2930 "k8s.io/apimachinery/pkg/runtime"
3031 "k8s.io/apimachinery/pkg/runtime/schema"
32+ "k8s.io/apimachinery/pkg/util/wait"
3133 "k8s.io/utils/ptr"
3234 "sigs.k8s.io/controller-runtime/pkg/client"
3335 "sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -38,7 +40,12 @@ import (
3840
3941func Test_WaitForCacheToBeUpToDate (t * testing.T ) {
4042 // Modify timeout to speed up test
41- waitForCacheTimeout = 1 * time .Second
43+ waitBackoff = wait.Backoff {
44+ Duration : 25 * time .Microsecond ,
45+ Cap : 2 * time .Second ,
46+ Factor : 1.2 ,
47+ Steps : 5 ,
48+ }
4249
4350 tests := []struct {
4451 name string
@@ -92,7 +99,7 @@ func Test_WaitForCacheToBeUpToDate(t *testing.T) {
9299 machine ("machine-4" , "4" , nil ),
93100 },
94101 clientResponses : map [client.ObjectKey ][]client.Object {},
95- wantErr : "failed to wait for up-to-date Machine objects in the cache after Machine creation: timed out after 1s : [" +
102+ wantErr : "failed to wait for up-to-date Machine objects in the cache after Machine creation: timed out: [" +
96103 "machines.cluster.x-k8s.io \" machine-1\" not found, " +
97104 "machines.cluster.x-k8s.io \" machine-2\" not found, " +
98105 "machines.cluster.x-k8s.io \" machine-3\" not found, " +
@@ -201,7 +208,12 @@ func Test_WaitForCacheToBeUpToDate(t *testing.T) {
201208
202209func Test_WaitForObjectsToBeDeletedFromTheCache (t * testing.T ) {
203210 // Modify timeout to speed up test
204- waitForCacheTimeout = 1 * time .Second
211+ waitBackoff = wait.Backoff {
212+ Duration : 25 * time .Microsecond ,
213+ Cap : 2 * time .Second ,
214+ Factor : 1.2 ,
215+ Steps : 5 ,
216+ }
205217
206218 tests := []struct {
207219 name string
@@ -212,6 +224,13 @@ func Test_WaitForObjectsToBeDeletedFromTheCache(t *testing.T) {
212224 {
213225 name : "no-op if no objects are passed in" ,
214226 },
227+ {
228+ name : "error if Unstructured is used" ,
229+ objs : []client.Object {
230+ & unstructured.Unstructured {},
231+ },
232+ wantErr : "failed to wait for up-to-date objects in the cache after Machine deletion: Unstructured is not supported" ,
233+ },
215234 {
216235 name : "success if objects are going away instantly (not found)" ,
217236 objs : []client.Object {
@@ -306,7 +325,7 @@ func Test_WaitForObjectsToBeDeletedFromTheCache(t *testing.T) {
306325 machine ("machine-4" , "7" , nil ),
307326 },
308327 },
309- wantErr : "failed to wait for up-to-date Machine objects in the cache after Machine deletion: timed out after 1s : [" +
328+ wantErr : "failed to wait for up-to-date Machine objects in the cache after Machine deletion: timed out: [" +
310329 "default/machine-1 still exists, " +
311330 "default/machine-2 still exists, " +
312331 "default/machine-3 still exists, " +
0 commit comments