@@ -18,7 +18,6 @@ package scheduling
1818
1919import (
2020 "context"
21- "sync"
2221 "testing"
2322
2423 "github.com/google/go-cmp/cmp"
@@ -60,9 +59,8 @@ func TestSchedule(t *testing.T) {
6059 // pod2 will be picked because it has relatively low queue size, with the requested
6160 // model being active, and has low KV cache.
6261 input : []* podinfo.FakePodInfo {
63- {
64- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }},
65- Data : map [string ]podinfo.ScrapedData {
62+ podinfo .NewFakePodInfo (k8stypes.NamespacedName {Name : "pod1" }).
63+ WithData (map [string ]podinfo.ScrapedData {
6664 metrics .MetricsDataKey : & backendmetrics.Metrics {
6765 WaitingQueueSize : 0 ,
6866 KVCacheUsagePercent : 0.2 ,
@@ -72,12 +70,9 @@ func TestSchedule(t *testing.T) {
7270 "bar" : 1 ,
7371 },
7472 },
75- },
76- Lock : sync.RWMutex {},
77- },
78- {
79- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod2" }},
80- Data : map [string ]podinfo.ScrapedData {
73+ }),
74+ podinfo .NewFakePodInfo (k8stypes.NamespacedName {Name : "pod2" }).
75+ WithData (map [string ]podinfo.ScrapedData {
8176 metrics .MetricsDataKey : & backendmetrics.Metrics {
8277 WaitingQueueSize : 3 ,
8378 KVCacheUsagePercent : 0.1 ,
@@ -87,11 +82,9 @@ func TestSchedule(t *testing.T) {
8782 "critical" : 1 ,
8883 },
8984 },
90- },
91- },
92- {
93- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod3" }},
94- Data : map [string ]podinfo.ScrapedData {
85+ }),
86+ podinfo .NewFakePodInfo (k8stypes.NamespacedName {Name : "pod3" }).
87+ WithData (map [string ]podinfo.ScrapedData {
9588 metrics .MetricsDataKey : & backendmetrics.Metrics {
9689 WaitingQueueSize : 10 ,
9790 KVCacheUsagePercent : 0.2 ,
@@ -100,8 +93,7 @@ func TestSchedule(t *testing.T) {
10093 "foo" : 1 ,
10194 },
10295 },
103- },
104- },
96+ }),
10597 },
10698 wantRes : & types.Result {
10799 TargetPod : & types.ScoredPod {
@@ -132,9 +124,8 @@ func TestSchedule(t *testing.T) {
132124 },
133125 // pod1 will be picked because it has capacity for the sheddable request.
134126 input : []* podinfo.FakePodInfo {
135- {
136- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }},
137- Data : map [string ]podinfo.ScrapedData {
127+ podinfo .NewFakePodInfo (k8stypes.NamespacedName {Name : "pod1" }).
128+ WithData (map [string ]podinfo.ScrapedData {
138129 metrics .MetricsDataKey : & backendmetrics.Metrics {
139130 WaitingQueueSize : 0 ,
140131 KVCacheUsagePercent : 0.2 ,
@@ -144,12 +135,9 @@ func TestSchedule(t *testing.T) {
144135 "bar" : 1 ,
145136 },
146137 },
147- },
148- Lock : sync.RWMutex {},
149- },
150- {
151- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod2" }},
152- Data : map [string ]podinfo.ScrapedData {
138+ }),
139+ podinfo .NewFakePodInfo (k8stypes.NamespacedName {Name : "pod2" }).
140+ WithData (map [string ]podinfo.ScrapedData {
153141 metrics .MetricsDataKey : & backendmetrics.Metrics {
154142 WaitingQueueSize : 3 ,
155143 KVCacheUsagePercent : 0.1 ,
@@ -159,11 +147,9 @@ func TestSchedule(t *testing.T) {
159147 "critical" : 1 ,
160148 },
161149 },
162- },
163- },
164- {
165- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod3" }},
166- Data : map [string ]podinfo.ScrapedData {
150+ }),
151+ podinfo .NewFakePodInfo (k8stypes.NamespacedName {Name : "pod3" }).
152+ WithData (map [string ]podinfo.ScrapedData {
167153 metrics .MetricsDataKey : & backendmetrics.Metrics {
168154 WaitingQueueSize : 10 ,
169155 KVCacheUsagePercent : 0.2 ,
@@ -172,8 +158,7 @@ func TestSchedule(t *testing.T) {
172158 "foo" : 1 ,
173159 },
174160 },
175- },
176- },
161+ }),
177162 },
178163 wantRes : & types.Result {
179164 TargetPod : & types.ScoredPod {
@@ -205,9 +190,8 @@ func TestSchedule(t *testing.T) {
205190 // All pods have higher KV cache thant the threshold, so the sheddable request will be
206191 // dropped.
207192 input : []* podinfo.FakePodInfo {
208- {
209- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }},
210- Data : map [string ]podinfo.ScrapedData {
193+ podinfo .NewFakePodInfo (k8stypes.NamespacedName {Name : "pod1" }).
194+ WithData (map [string ]podinfo.ScrapedData {
211195 metrics .MetricsDataKey : & backendmetrics.Metrics {
212196 WaitingQueueSize : 10 ,
213197 KVCacheUsagePercent : 0.9 ,
@@ -217,12 +201,9 @@ func TestSchedule(t *testing.T) {
217201 "bar" : 1 ,
218202 },
219203 },
220- },
221- Lock : sync.RWMutex {},
222- },
223- {
224- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod2" }},
225- Data : map [string ]podinfo.ScrapedData {
204+ }),
205+ podinfo .NewFakePodInfo (k8stypes.NamespacedName {Name : "pod2" }).
206+ WithData (map [string ]podinfo.ScrapedData {
226207 metrics .MetricsDataKey : & backendmetrics.Metrics {
227208 WaitingQueueSize : 3 ,
228209 KVCacheUsagePercent : 0.85 ,
@@ -232,11 +213,9 @@ func TestSchedule(t *testing.T) {
232213 "critical" : 1 ,
233214 },
234215 },
235- },
236- },
237- {
238- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod3" }},
239- Data : map [string ]podinfo.ScrapedData {
216+ }),
217+ podinfo .NewFakePodInfo (k8stypes.NamespacedName {Name : "pod3" }).
218+ WithData (map [string ]podinfo.ScrapedData {
240219 metrics .MetricsDataKey : & backendmetrics.Metrics {
241220 WaitingQueueSize : 10 ,
242221 KVCacheUsagePercent : 0.85 ,
@@ -245,8 +224,7 @@ func TestSchedule(t *testing.T) {
245224 "foo" : 1 ,
246225 },
247226 },
248- },
249- },
227+ }),
250228 },
251229 wantRes : nil ,
252230 err : true ,
@@ -311,9 +289,9 @@ func TestSchedulePlugins(t *testing.T) {
311289 postSchedulePlugins : []plugins.PostSchedule {tp1 , tp2 },
312290 },
313291 input : []* podinfo.FakePodInfo {
314- { Pod : & backend. Pod { NamespacedName : k8stypes.NamespacedName {Name : "pod1" }}, Lock : sync. RWMutex {}} ,
315- { Pod : & backend. Pod { NamespacedName : k8stypes.NamespacedName {Name : "pod2" }}, Lock : sync. RWMutex {}} ,
316- { Pod : & backend. Pod { NamespacedName : k8stypes.NamespacedName {Name : "pod3" }}, Lock : sync. RWMutex {}} ,
292+ podinfo . NewFakePodInfo ( k8stypes.NamespacedName {Name : "pod1" }) ,
293+ podinfo . NewFakePodInfo ( k8stypes.NamespacedName {Name : "pod2" }) ,
294+ podinfo . NewFakePodInfo ( k8stypes.NamespacedName {Name : "pod3" }) ,
317295 },
318296 wantTargetPod : k8stypes.NamespacedName {Name : "pod1" },
319297 targetPodScore : 1.1 ,
@@ -333,9 +311,9 @@ func TestSchedulePlugins(t *testing.T) {
333311 postSchedulePlugins : []plugins.PostSchedule {tp1 , tp2 },
334312 },
335313 input : []* podinfo.FakePodInfo {
336- { Pod : & backend. Pod { NamespacedName : k8stypes.NamespacedName {Name : "pod1" }}, Lock : sync. RWMutex {}} ,
337- { Pod : & backend. Pod { NamespacedName : k8stypes.NamespacedName {Name : "pod2" }}, Lock : sync. RWMutex {}} ,
338- { Pod : & backend. Pod { NamespacedName : k8stypes.NamespacedName {Name : "pod3" }}, Lock : sync. RWMutex {}} ,
314+ podinfo . NewFakePodInfo ( k8stypes.NamespacedName {Name : "pod1" }) ,
315+ podinfo . NewFakePodInfo ( k8stypes.NamespacedName {Name : "pod2" }) ,
316+ podinfo . NewFakePodInfo ( k8stypes.NamespacedName {Name : "pod3" }) ,
339317 },
340318 wantTargetPod : k8stypes.NamespacedName {Name : "pod1" },
341319 targetPodScore : 50 ,
@@ -355,9 +333,9 @@ func TestSchedulePlugins(t *testing.T) {
355333 postSchedulePlugins : []plugins.PostSchedule {tp1 , tp2 },
356334 },
357335 input : []* podinfo.FakePodInfo {
358- { Pod : & backend. Pod { NamespacedName : k8stypes.NamespacedName {Name : "pod1" }}, Lock : sync. RWMutex {}} ,
359- { Pod : & backend. Pod { NamespacedName : k8stypes.NamespacedName {Name : "pod2" }}, Lock : sync. RWMutex {}} ,
360- { Pod : & backend. Pod { NamespacedName : k8stypes.NamespacedName {Name : "pod3" }}, Lock : sync. RWMutex {}} ,
336+ podinfo . NewFakePodInfo ( k8stypes.NamespacedName {Name : "pod1" }) ,
337+ podinfo . NewFakePodInfo ( k8stypes.NamespacedName {Name : "pod2" }) ,
338+ podinfo . NewFakePodInfo ( k8stypes.NamespacedName {Name : "pod3" }) ,
361339 },
362340 numPodsToScore : 0 ,
363341 err : true , // no available pods to server after filter all
0 commit comments