@@ -44,7 +44,7 @@ import (
44
44
"errors"
45
45
"fmt"
46
46
"os"
47
- "slices "
47
+ "sort "
48
48
"sync"
49
49
"sync/atomic"
50
50
"testing"
@@ -122,7 +122,7 @@ type testHarness struct {
122
122
// The harness's mutex protects the single source of truth for all mock state.
123
123
mu sync.Mutex
124
124
queues map [types.FlowKey ]* mocks.MockManagedQueue
125
- priorityFlows map [uint ][]types.FlowKey // Key: `priority`
125
+ priorityFlows map [int ][]types.FlowKey // Key: `priority`
126
126
127
127
// Customizable policy logic for tests to override.
128
128
interFlowPolicySelectQueue func (band framework.PriorityBandAccessor ) (framework.FlowQueueAccessor , error )
@@ -139,7 +139,7 @@ func newTestHarness(t *testing.T, expiryCleanupInterval time.Duration) *testHarn
139
139
logger : logr .Discard (),
140
140
startSignal : make (chan struct {}),
141
141
queues : make (map [types.FlowKey ]* mocks.MockManagedQueue ),
142
- priorityFlows : make (map [uint ][]types.FlowKey ),
142
+ priorityFlows : make (map [int ][]types.FlowKey ),
143
143
}
144
144
145
145
// 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
153
153
h .StatsFunc = func () contracts.ShardStats {
154
154
return contracts.ShardStats {
155
155
TotalCapacityBytes : 1e9 ,
156
- PerPriorityBandStats : map [uint ]contracts.PriorityBandStats {
156
+ PerPriorityBandStats : map [int ]contracts.PriorityBandStats {
157
157
testFlow .Priority : {CapacityBytes : 1e9 },
158
158
},
159
159
}
@@ -249,20 +249,23 @@ func (h *testHarness) managedQueue(key types.FlowKey) (contracts.ManagedQueue, e
249
249
}
250
250
251
251
// allOrderedPriorityLevels provides the mock implementation for the `RegistryShard` interface.
252
- func (h * testHarness ) allOrderedPriorityLevels () []uint {
252
+ func (h * testHarness ) allOrderedPriorityLevels () []int {
253
253
h .mu .Lock ()
254
254
defer h .mu .Unlock ()
255
- prios := make ([]uint , 0 , len (h .priorityFlows ))
255
+ prios := make ([]int , 0 , len (h .priorityFlows ))
256
256
for p := range h .priorityFlows {
257
257
prios = append (prios , p )
258
258
}
259
- slices .Sort (prios )
259
+ sort .Slice (prios , func (i , j int ) bool {
260
+ return prios [i ] > prios [j ]
261
+ })
262
+
260
263
return prios
261
264
}
262
265
263
266
// priorityBandAccessor provides the mock implementation for the `RegistryShard` interface. It acts as a factory for a
264
267
// 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 ) {
266
269
band := & frameworkmocks.MockPriorityBandAccessor {PriorityV : p }
267
270
268
271
// Safely get a snapshot of the flow IDs under a lock.
@@ -288,7 +291,7 @@ func (h *testHarness) priorityBandAccessor(p uint) (framework.PriorityBandAccess
288
291
}
289
292
290
293
// 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 ) {
292
295
policy := & frameworkmocks.MockInterFlowDispatchPolicy {}
293
296
// If the test provided a custom implementation, use it.
294
297
if h .interFlowPolicySelectQueue != nil {
@@ -362,7 +365,7 @@ func TestShardProcessor(t *testing.T) {
362
365
item := h .newTestItem ("req-capacity-reject" , testFlow , testTTL )
363
366
h .addQueue (testFlow )
364
367
h .StatsFunc = func () contracts.ShardStats {
365
- return contracts.ShardStats {PerPriorityBandStats : map [uint ]contracts.PriorityBandStats {
368
+ return contracts.ShardStats {PerPriorityBandStats : map [int ]contracts.PriorityBandStats {
366
369
testFlow .Priority : {CapacityBytes : 50 }, // 50 is less than item size of 100
367
370
}}
368
371
}
@@ -685,7 +688,7 @@ func TestShardProcessor(t *testing.T) {
685
688
name : "should reject item on registry priority band lookup failure" ,
686
689
setupHarness : func (h * testHarness ) {
687
690
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 }
689
692
},
690
693
assert : func (t * testing.T , h * testHarness , item * flowItem ) {
691
694
outcome , err := item .FinalState ()
@@ -776,7 +779,7 @@ func TestShardProcessor(t *testing.T) {
776
779
itemByteSize : 1 ,
777
780
stats : contracts.ShardStats {
778
781
TotalCapacityBytes : 200 , TotalByteSize : 100 ,
779
- PerPriorityBandStats : map [uint ]contracts.PriorityBandStats {
782
+ PerPriorityBandStats : map [int ]contracts.PriorityBandStats {
780
783
testFlow .Priority : {ByteSize : 50 , CapacityBytes : 50 },
781
784
},
782
785
},
@@ -787,7 +790,7 @@ func TestShardProcessor(t *testing.T) {
787
790
itemByteSize : 1 ,
788
791
stats : contracts.ShardStats {
789
792
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
791
794
},
792
795
expectHasCap : false ,
793
796
},
@@ -796,7 +799,7 @@ func TestShardProcessor(t *testing.T) {
796
799
itemByteSize : 10 ,
797
800
stats : contracts.ShardStats {
798
801
TotalCapacityBytes : 200 , TotalByteSize : 100 ,
799
- PerPriorityBandStats : map [uint ]contracts.PriorityBandStats {
802
+ PerPriorityBandStats : map [int ]contracts.PriorityBandStats {
800
803
testFlow .Priority : {ByteSize : 50 , CapacityBytes : 100 },
801
804
},
802
805
},
@@ -854,7 +857,7 @@ func TestShardProcessor(t *testing.T) {
854
857
{
855
858
name : "should skip band on priority band accessor error" ,
856
859
setupHarness : func (h * testHarness ) {
857
- h .PriorityBandAccessorFunc = func (uint ) (framework.PriorityBandAccessor , error ) {
860
+ h .PriorityBandAccessorFunc = func (int ) (framework.PriorityBandAccessor , error ) {
858
861
return nil , registryErr
859
862
}
860
863
},
@@ -1003,8 +1006,8 @@ func TestShardProcessor(t *testing.T) {
1003
1006
t .Parallel ()
1004
1007
// --- ARRANGE ---
1005
1008
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 }
1008
1011
qHigh := h .addQueue (keyHigh )
1009
1012
qLow := h .addQueue (keyLow )
1010
1013
@@ -1196,8 +1199,8 @@ func TestShardProcessor(t *testing.T) {
1196
1199
t .Parallel ()
1197
1200
// --- ARRANGE ---
1198
1201
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 ) {
1201
1204
return nil , errors .New ("registry error" )
1202
1205
}
1203
1206
0 commit comments