Skip to content

Commit 3086b58

Browse files
committed
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.
1 parent c69f150 commit 3086b58

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

staging/src/k8s.io/dynamic-resource-allocation/resourceslice/resourceslicecontroller_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func TestControllerSyncPool(t *testing.T) {
145145
},
146146
"remove-pool": {
147147
nodeUID: nodeUID,
148-
syncDelay: ptr.To(time.Duration(0)),
148+
syncDelay: ptr.To(time.Duration(0)), // Ensure that the initial object causes an immediate sync of the pool.
149149
initialObjects: []runtime.Object{
150150
MakeResourceSlice().Name(resourceSlice1).UID(resourceSlice1).
151151
NodeOwnerReferences(ownerName, string(nodeUID)).NodeName(ownerName).
@@ -683,6 +683,11 @@ func TestControllerSyncPool(t *testing.T) {
683683
// from informer event handler).
684684
actualState := queue.State()
685685
actualState.Later = nil
686+
// If we let the event handler schedule syncs immediately, then that also races
687+
// and then Ready cannot be compared either.
688+
if test.syncDelay != nil && *test.syncDelay == 0 {
689+
actualState.Ready = nil
690+
}
686691
var expectState workqueue.MockState[string]
687692
assert.Equal(t, expectState, actualState)
688693
})

0 commit comments

Comments
 (0)