From 3086b58460864350c79fd50e00d970eb51bf6c90 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 5 Nov 2024 17:16:48 +0100 Subject: [PATCH] DRA resource slice controller: fix unit test flake The TestControllerSyncPool/remove-pool flaked because it intentionally runs with no sync delay, in which case the delete event may add the pool again to the ready queue directly. This raced with checking the queue state where "no pools in ready queue" was expected. The solution is to relax checking in this particular case and exclude the ready queue. --- .../resourceslice/resourceslicecontroller_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/dynamic-resource-allocation/resourceslice/resourceslicecontroller_test.go b/staging/src/k8s.io/dynamic-resource-allocation/resourceslice/resourceslicecontroller_test.go index dd461d35251..5b20362f6cd 100644 --- a/staging/src/k8s.io/dynamic-resource-allocation/resourceslice/resourceslicecontroller_test.go +++ b/staging/src/k8s.io/dynamic-resource-allocation/resourceslice/resourceslicecontroller_test.go @@ -145,7 +145,7 @@ func TestControllerSyncPool(t *testing.T) { }, "remove-pool": { nodeUID: nodeUID, - syncDelay: ptr.To(time.Duration(0)), + syncDelay: ptr.To(time.Duration(0)), // Ensure that the initial object causes an immediate sync of the pool. initialObjects: []runtime.Object{ MakeResourceSlice().Name(resourceSlice1).UID(resourceSlice1). NodeOwnerReferences(ownerName, string(nodeUID)).NodeName(ownerName). @@ -683,6 +683,11 @@ func TestControllerSyncPool(t *testing.T) { // from informer event handler). actualState := queue.State() actualState.Later = nil + // If we let the event handler schedule syncs immediately, then that also races + // and then Ready cannot be compared either. + if test.syncDelay != nil && *test.syncDelay == 0 { + actualState.Ready = nil + } var expectState workqueue.MockState[string] assert.Equal(t, expectState, actualState) })