@@ -48,19 +48,21 @@ func newTestComparator() *frameworkmocks.MockItemComparator {
48
48
}
49
49
}
50
50
51
- func newTestBand (queues map [ string ] framework.FlowQueueAccessor ) * frameworkmocks.MockPriorityBandAccessor {
51
+ func newTestBand (queues ... framework.FlowQueueAccessor ) * frameworkmocks.MockPriorityBandAccessor {
52
52
flowIDs := make ([]string , 0 , len (queues ))
53
- for id := range queues {
54
- flowIDs = append (flowIDs , id )
53
+ queuesByID := make (map [string ]framework.FlowQueueAccessor , len (queues ))
54
+ for _ , q := range queues {
55
+ flowIDs = append (flowIDs , q .FlowSpec ().ID )
56
+ queuesByID [q .FlowSpec ().ID ] = q
55
57
}
56
58
return & frameworkmocks.MockPriorityBandAccessor {
57
59
FlowIDsFunc : func () []string { return flowIDs },
58
60
QueueFunc : func (id string ) framework.FlowQueueAccessor {
59
- return queues [id ]
61
+ return queuesByID [id ]
60
62
},
61
63
IterateQueuesFunc : func (iterator func (queue framework.FlowQueueAccessor ) bool ) {
62
64
for _ , id := range flowIDs {
63
- if ! iterator (queues [id ]) {
65
+ if ! iterator (queuesByID [id ]) {
64
66
break
65
67
}
66
68
}
@@ -111,90 +113,88 @@ func TestBestHead_SelectQueue(t *testing.T) {
111
113
shouldPanic bool
112
114
}{
113
115
{
114
- name : "BasicSelection_TwoQueues" ,
115
- band : newTestBand (map [string ]framework.FlowQueueAccessor {
116
- flow1 : queue1 ,
117
- flow2 : queue2 ,
118
- }),
116
+ name : "BasicSelection_TwoQueues" ,
117
+ band : newTestBand (queue1 , queue2 ),
119
118
expectedQueueID : flow1 ,
120
119
},
121
120
{
122
- name : "IgnoresEmptyQueues" ,
123
- band : newTestBand (map [string ]framework.FlowQueueAccessor {
124
- flow1 : queue1 ,
125
- "flowEmpty" : queueEmpty ,
126
- flow2 : queue2 ,
127
- }),
121
+ name : "IgnoresEmptyQueues" ,
122
+ band : newTestBand (queue1 , queueEmpty , queue2 ),
128
123
expectedQueueID : flow1 ,
129
124
},
130
125
{
131
126
name : "SingleNonEmptyQueue" ,
132
- band : newTestBand (map [ string ]framework. FlowQueueAccessor { flow1 : queue1 } ),
127
+ band : newTestBand (queue1 ),
133
128
expectedQueueID : flow1 ,
134
129
},
135
130
{
136
131
name : "ComparatorCompatibility" ,
137
- band : newTestBand (map [ string ]framework. FlowQueueAccessor {
138
- flow1 : & frameworkmocks.MockFlowQueueAccessor {
132
+ band : newTestBand (
133
+ & frameworkmocks.MockFlowQueueAccessor {
139
134
LenV : 1 ,
140
135
PeekHeadV : itemBetter ,
141
136
FlowSpecV : types.FlowSpecification {ID : flow1 },
142
137
ComparatorV : & frameworkmocks.MockItemComparator {ScoreTypeV : "typeA" , FuncV : enqueueTimeComparatorFunc },
143
138
},
144
- flow2 : & frameworkmocks.MockFlowQueueAccessor {
139
+ & frameworkmocks.MockFlowQueueAccessor {
145
140
LenV : 1 ,
146
141
PeekHeadV : itemWorse ,
147
142
FlowSpecV : types.FlowSpecification {ID : flow2 },
148
143
ComparatorV : & frameworkmocks.MockItemComparator {ScoreTypeV : "typeB" , FuncV : enqueueTimeComparatorFunc },
149
144
},
150
- } ),
145
+ ),
151
146
expectedErr : framework .ErrIncompatiblePriorityType ,
152
147
},
153
148
{
154
149
name : "QueuePeekHeadErrors" ,
155
- band : newTestBand (map [ string ]framework. FlowQueueAccessor {
156
- flow1 : & frameworkmocks.MockFlowQueueAccessor {
150
+ band : newTestBand (
151
+ & frameworkmocks.MockFlowQueueAccessor {
157
152
LenV : 1 ,
158
153
PeekHeadErrV : errors .New ("peek error" ),
159
154
FlowSpecV : types.FlowSpecification {ID : flow1 },
160
155
ComparatorV : newTestComparator (),
161
156
},
162
- flow2 : queue2 ,
163
- } ),
157
+ queue2 ,
158
+ ),
164
159
expectedQueueID : flow2 ,
165
160
},
166
161
{
167
162
name : "QueueComparatorIsNil" ,
168
- band : newTestBand (map [ string ]framework. FlowQueueAccessor {
169
- flow1 : & frameworkmocks.MockFlowQueueAccessor {
163
+ band : newTestBand (
164
+ & frameworkmocks.MockFlowQueueAccessor {
170
165
LenV : 1 ,
171
166
PeekHeadV : itemBetter ,
172
167
FlowSpecV : types.FlowSpecification {ID : flow1 },
173
168
ComparatorV : nil ,
174
169
},
175
- flow2 : queue2 ,
176
- } ),
170
+ queue2 ,
171
+ ),
177
172
shouldPanic : true ,
178
173
},
179
174
{
180
175
name : "ComparatorFuncIsNil" ,
181
- band : newTestBand (map [ string ]framework. FlowQueueAccessor {
182
- flow1 : & frameworkmocks.MockFlowQueueAccessor {
176
+ band : newTestBand (
177
+ & frameworkmocks.MockFlowQueueAccessor {
183
178
LenV : 1 ,
184
179
PeekHeadV : itemBetter ,
185
180
FlowSpecV : types.FlowSpecification {ID : flow1 },
186
181
ComparatorV : & frameworkmocks.MockItemComparator {ScoreTypeV : commonScoreType , FuncV : nil },
187
182
},
188
- flow2 : queue2 ,
189
- } ),
183
+ queue2 ,
184
+ ),
190
185
shouldPanic : true ,
191
186
},
192
187
{
193
188
name : "AllQueuesEmpty" ,
194
- band : newTestBand (map [string ]framework.FlowQueueAccessor {
195
- "empty1" : queueEmpty ,
196
- "empty2" : queueEmpty ,
197
- }),
189
+ band : newTestBand (
190
+ queueEmpty ,
191
+ & frameworkmocks.MockFlowQueueAccessor {
192
+ LenV : 0 ,
193
+ PeekHeadErrV : framework .ErrQueueEmpty ,
194
+ FlowSpecV : types.FlowSpecification {ID : "flowEmpty2" },
195
+ ComparatorV : newTestComparator (),
196
+ },
197
+ ),
198
198
},
199
199
{
200
200
name : "NilBand" ,
0 commit comments