package workqueue
import "k8s.io/dynamic-resource-allocation/internal/workqueue"
Index ¶
- type Mock
- func (m *Mock[T]) Add(item T)
- func (m *Mock[T]) AddAfter(item T, duration time.Duration)
- func (m *Mock[T]) AddRateLimited(item T)
- func (m *Mock[T]) Done(item T)
- func (m *Mock[T]) Forget(item T)
- func (m *Mock[T]) Get() (item T, shutdown bool)
- func (m *Mock[T]) Len() int
- func (m *Mock[T]) NumRequeues(item T) int
- func (m *Mock[T]) ShutDown()
- func (m *Mock[T]) ShutDownWithDrain()
- func (m *Mock[T]) ShuttingDown() bool
- func (m *Mock[T]) State() MockState[T]
- func (m *Mock[T]) SyncOne(item T, sync func(workqueue.TypedRateLimitingInterface[T]))
- type MockDelayedItem
- type MockState
Types ¶
type Mock ¶
type Mock[T comparable] struct { // contains filtered or unexported fields }
MockQueue is an implementation of [TypedRateLimitingInterface] which can be used to test a function which pulls work items out of a queue and processes them. It is thread-safe.
A null instance is directly usable. The usual usage is:
var m workqueue.Mock[string] m.SyncOne("some-item", func(queue workqueue.TypedRateLimitingInterface[string]) { ... } ) if diff := cmp.Diff(workqueue.MockState[string]{}, m.State()); diff != "" { t.Errorf("unexpected state of mock work queue after sync (-want, +got):\n%s", diff) }
All slices get reset to nil when they become empty, so there are no spurious differences because of nil vs. empty slice.
func (*Mock[T]) Add ¶
func (m *Mock[T]) Add(item T)
Add implements [TypedInterface].
func (*Mock[T]) AddAfter ¶
AddAfter implements [TypedDelayingInterface.AddAfter]
func (*Mock[T]) AddRateLimited ¶
func (m *Mock[T]) AddRateLimited(item T)
AddRateLimited implements [TypedRateLimitingInterface.AddRateLimited].
func (*Mock[T]) Done ¶
func (m *Mock[T]) Done(item T)
Done implements [TypedInterface].
func (*Mock[T]) Forget ¶
func (m *Mock[T]) Forget(item T)
Forget implements [TypedRateLimitingInterface.Forget].
func (*Mock[T]) Get ¶
Get implements [TypedInterface].
func (*Mock[T]) Len ¶
Len implements [TypedInterface].
func (*Mock[T]) NumRequeues ¶
NumRequeues implements [TypedRateLimitingInterface.NumRequeues].
func (*Mock[T]) ShutDown ¶
func (m *Mock[T]) ShutDown()
ShutDown implements [TypedInterface].
func (*Mock[T]) ShutDownWithDrain ¶
func (m *Mock[T]) ShutDownWithDrain()
ShutDownWithDrain implements [TypedInterface].
func (*Mock[T]) ShuttingDown ¶
ShuttingDown implements [TypedInterface].
func (*Mock[T]) State ¶
State returns the current state of the queue.
func (*Mock[T]) SyncOne ¶
func (m *Mock[T]) SyncOne(item T, sync func(workqueue.TypedRateLimitingInterface[T]))
SyncOne adds the item to the work queue and calls sync. That sync function can pull one or more items from the work queue until the queue is empty. Then it is told that the queue is shutting down, which must cause it to return.
The test can then retrieve the state of the queue to check the result.
type MockDelayedItem ¶
type MockDelayedItem[T comparable] struct { Item T Duration time.Duration }
MockDelayedItem is an item which was queue for later processing.
type MockState ¶
type MockState[T comparable] struct { // Ready contains the items which are ready for processing. Ready []T // InFlight contains the items which are currently being processed (= Get // was called, Done not yet). InFlight []T // MismatchedDone contains the items for which Done was called without // a matching Get. MismatchedDone []T // Later contains the items which are meant to be added to the queue after // a certain delay (= AddAfter was called for them). They appear in the // order in which AddAfter got called. Later []MockDelayedItem[T] // Failures contains the items and their retry count which failed to be // processed (AddRateLimited called at least once, Forget not yet). // The retry count is always larger than zero. Failures map[T]int // ShutDownCalled tracks how often ShutDown got called. ShutDownCalled int // ShutDownWithDrainCalled tracks how often ShutDownWithDrain got called. ShutDownWithDrainCalled int }
func (MockState[T]) DeepCopy ¶
DeepCopy takes a snapshot of all slices. It cannot do a deep copy of the items in those slices, but typically those keys are immutable.
Source Files ¶
mockqueue.go
- Version
- v0.33.0 (latest)
- Published
- Apr 23, 2025
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 1 month ago –
Tools for package owners.