@@ -44,7 +44,7 @@ import (
4444 "errors"
4545 "fmt"
4646 "os"
47- "slices "
47+ "sort "
4848 "sync"
4949 "sync/atomic"
5050 "testing"
@@ -122,7 +122,7 @@ type testHarness struct {
122122 // The harness's mutex protects the single source of truth for all mock state.
123123 mu sync.Mutex
124124 queues map [types.FlowKey ]* mocks.MockManagedQueue
125- priorityFlows map [uint ][]types.FlowKey // Key: `priority`
125+ priorityFlows map [int ][]types.FlowKey // Key: `priority`
126126
127127 // Customizable policy logic for tests to override.
128128 interFlowPolicySelectQueue func (band framework.PriorityBandAccessor ) (framework.FlowQueueAccessor , error )
@@ -139,7 +139,7 @@ func newTestHarness(t *testing.T, expiryCleanupInterval time.Duration) *testHarn
139139 logger : logr .Discard (),
140140 startSignal : make (chan struct {}),
141141 queues : make (map [types.FlowKey ]* mocks.MockManagedQueue ),
142- priorityFlows : make (map [uint ][]types.FlowKey ),
142+ priorityFlows : make (map [int ][]types.FlowKey ),
143143 }
144144
145145 // Wire up the harness to provide the mock implementations for the shard's dependencies.
@@ -153,7 +153,7 @@ func newTestHarness(t *testing.T, expiryCleanupInterval time.Duration) *testHarn
153153 h .StatsFunc = func () contracts.ShardStats {
154154 return contracts.ShardStats {
155155 TotalCapacityBytes : 1e9 ,
156- PerPriorityBandStats : map [uint ]contracts.PriorityBandStats {
156+ PerPriorityBandStats : map [int ]contracts.PriorityBandStats {
157157 testFlow .Priority : {CapacityBytes : 1e9 },
158158 },
159159 }
@@ -249,20 +249,23 @@ func (h *testHarness) managedQueue(key types.FlowKey) (contracts.ManagedQueue, e
249249}
250250
251251// allOrderedPriorityLevels provides the mock implementation for the `RegistryShard` interface.
252- func (h * testHarness ) allOrderedPriorityLevels () []uint {
252+ func (h * testHarness ) allOrderedPriorityLevels () []int {
253253 h .mu .Lock ()
254254 defer h .mu .Unlock ()
255- prios := make ([]uint , 0 , len (h .priorityFlows ))
255+ prios := make ([]int , 0 , len (h .priorityFlows ))
256256 for p := range h .priorityFlows {
257257 prios = append (prios , p )
258258 }
259- slices .Sort (prios )
259+ sort .Slice (prios , func (i , j int ) bool {
260+ return prios [i ] > prios [j ]
261+ })
262+
260263 return prios
261264}
262265
263266// priorityBandAccessor provides the mock implementation for the `RegistryShard` interface. It acts as a factory for a
264267// fully-configured, stateless mock that is safe for concurrent use.
265- func (h * testHarness ) priorityBandAccessor (p uint ) (framework.PriorityBandAccessor , error ) {
268+ func (h * testHarness ) priorityBandAccessor (p int ) (framework.PriorityBandAccessor , error ) {
266269 band := & frameworkmocks.MockPriorityBandAccessor {PriorityV : p }
267270
268271 // Safely get a snapshot of the flow IDs under a lock.
@@ -288,7 +291,7 @@ func (h *testHarness) priorityBandAccessor(p uint) (framework.PriorityBandAccess
288291}
289292
290293// interFlowDispatchPolicy provides the mock implementation for the `contracts.RegistryShard` interface.
291- func (h * testHarness ) interFlowDispatchPolicy (p uint ) (framework.InterFlowDispatchPolicy , error ) {
294+ func (h * testHarness ) interFlowDispatchPolicy (p int ) (framework.InterFlowDispatchPolicy , error ) {
292295 policy := & frameworkmocks.MockInterFlowDispatchPolicy {}
293296 // If the test provided a custom implementation, use it.
294297 if h .interFlowPolicySelectQueue != nil {
@@ -362,7 +365,7 @@ func TestShardProcessor(t *testing.T) {
362365 item := h .newTestItem ("req-capacity-reject" , testFlow , testTTL )
363366 h .addQueue (testFlow )
364367 h .StatsFunc = func () contracts.ShardStats {
365- return contracts.ShardStats {PerPriorityBandStats : map [uint ]contracts.PriorityBandStats {
368+ return contracts.ShardStats {PerPriorityBandStats : map [int ]contracts.PriorityBandStats {
366369 testFlow .Priority : {CapacityBytes : 50 }, // 50 is less than item size of 100
367370 }}
368371 }
@@ -685,7 +688,7 @@ func TestShardProcessor(t *testing.T) {
685688 name : "should reject item on registry priority band lookup failure" ,
686689 setupHarness : func (h * testHarness ) {
687690 h .addQueue (testFlow )
688- h .PriorityBandAccessorFunc = func (uint ) (framework.PriorityBandAccessor , error ) { return nil , testErr }
691+ h .PriorityBandAccessorFunc = func (int ) (framework.PriorityBandAccessor , error ) { return nil , testErr }
689692 },
690693 assert : func (t * testing.T , h * testHarness , item * flowItem ) {
691694 outcome , err := item .FinalState ()
@@ -776,7 +779,7 @@ func TestShardProcessor(t *testing.T) {
776779 itemByteSize : 1 ,
777780 stats : contracts.ShardStats {
778781 TotalCapacityBytes : 200 , TotalByteSize : 100 ,
779- PerPriorityBandStats : map [uint ]contracts.PriorityBandStats {
782+ PerPriorityBandStats : map [int ]contracts.PriorityBandStats {
780783 testFlow .Priority : {ByteSize : 50 , CapacityBytes : 50 },
781784 },
782785 },
@@ -787,7 +790,7 @@ func TestShardProcessor(t *testing.T) {
787790 itemByteSize : 1 ,
788791 stats : contracts.ShardStats {
789792 TotalCapacityBytes : 200 , TotalByteSize : 100 ,
790- PerPriorityBandStats : map [uint ]contracts.PriorityBandStats {}, // Missing stats for priority 10
793+ PerPriorityBandStats : map [int ]contracts.PriorityBandStats {}, // Missing stats for priority 10
791794 },
792795 expectHasCap : false ,
793796 },
@@ -796,7 +799,7 @@ func TestShardProcessor(t *testing.T) {
796799 itemByteSize : 10 ,
797800 stats : contracts.ShardStats {
798801 TotalCapacityBytes : 200 , TotalByteSize : 100 ,
799- PerPriorityBandStats : map [uint ]contracts.PriorityBandStats {
802+ PerPriorityBandStats : map [int ]contracts.PriorityBandStats {
800803 testFlow .Priority : {ByteSize : 50 , CapacityBytes : 100 },
801804 },
802805 },
@@ -854,7 +857,7 @@ func TestShardProcessor(t *testing.T) {
854857 {
855858 name : "should skip band on priority band accessor error" ,
856859 setupHarness : func (h * testHarness ) {
857- h .PriorityBandAccessorFunc = func (uint ) (framework.PriorityBandAccessor , error ) {
860+ h .PriorityBandAccessorFunc = func (int ) (framework.PriorityBandAccessor , error ) {
858861 return nil , registryErr
859862 }
860863 },
@@ -1003,8 +1006,8 @@ func TestShardProcessor(t *testing.T) {
10031006 t .Parallel ()
10041007 // --- ARRANGE ---
10051008 h := newTestHarness (t , testCleanupTick )
1006- keyHigh := types.FlowKey {ID : "flow-high" , Priority : 10 }
1007- keyLow := types.FlowKey {ID : "flow-low" , Priority : 20 }
1009+ keyHigh := types.FlowKey {ID : "flow-high" , Priority : 20 }
1010+ keyLow := types.FlowKey {ID : "flow-low" , Priority : 10 }
10081011 qHigh := h .addQueue (keyHigh )
10091012 qLow := h .addQueue (keyLow )
10101013
@@ -1196,8 +1199,8 @@ func TestShardProcessor(t *testing.T) {
11961199 t .Parallel ()
11971200 // --- ARRANGE ---
11981201 h := newTestHarness (t , testCleanupTick )
1199- h .AllOrderedPriorityLevelsFunc = func () []uint { return []uint {testFlow .Priority } }
1200- h .PriorityBandAccessorFunc = func (p uint ) (framework.PriorityBandAccessor , error ) {
1202+ h .AllOrderedPriorityLevelsFunc = func () []int { return []int {testFlow .Priority } }
1203+ h .PriorityBandAccessorFunc = func (p int ) (framework.PriorityBandAccessor , error ) {
12011204 return nil , errors .New ("registry error" )
12021205 }
12031206
0 commit comments