@@ -206,44 +206,38 @@ func TestKubeInferenceModelRequest(t *testing.T) {
206
206
},
207
207
}
208
208
209
- pods := []* backend.PodMetrics {
209
+ metrics := []* backend.Metrics {
210
210
{
211
- Metrics : backend.Metrics {
212
- WaitingQueueSize : 0 ,
213
- KVCacheUsagePercent : 0.2 ,
214
- ActiveModels : map [string ]int {
215
- "foo" : 1 ,
216
- "bar" : 1 ,
217
- },
211
+ WaitingQueueSize : 0 ,
212
+ KVCacheUsagePercent : 0.2 ,
213
+ ActiveModels : map [string ]int {
214
+ "foo" : 1 ,
215
+ "bar" : 1 ,
218
216
},
219
217
},
220
218
{
221
- Metrics : backend.Metrics {
222
- WaitingQueueSize : 0 ,
223
- KVCacheUsagePercent : 0.1 ,
224
- ActiveModels : map [string ]int {
225
- "foo" : 1 ,
226
- "sql-lora-1fdg2" : 1 ,
227
- },
219
+ WaitingQueueSize : 0 ,
220
+ KVCacheUsagePercent : 0.1 ,
221
+ ActiveModels : map [string ]int {
222
+ "foo" : 1 ,
223
+ "sql-lora-1fdg2" : 1 ,
228
224
},
229
225
},
230
226
{
231
- Metrics : backend.Metrics {
232
- WaitingQueueSize : 10 ,
233
- KVCacheUsagePercent : 0.2 ,
234
- ActiveModels : map [string ]int {
235
- "foo" : 1 ,
236
- },
227
+ WaitingQueueSize : 10 ,
228
+ KVCacheUsagePercent : 0.2 ,
229
+ ActiveModels : map [string ]int {
230
+ "foo" : 1 ,
237
231
},
238
232
},
239
233
}
240
234
241
235
// Set up global k8sclient and extproc server runner with test environment config
242
- BeforeSuit (pods )
236
+ podMetrics := BeforeSuit (metrics )
243
237
244
238
for _ , test := range tests {
245
239
t .Run (test .name , func (t * testing.T ) {
246
- client , cleanup := setUpHermeticServer (t , pods )
240
+ client , cleanup := setUpHermeticServer (t , podMetrics )
247
241
t .Cleanup (cleanup )
248
242
want := & extProcPb.ProcessingResponse {
249
243
Response : & extProcPb.ProcessingResponse_RequestBody {
@@ -374,7 +368,7 @@ func setUpHermeticServer(t *testing.T, pods []*backend.PodMetrics) (client extPr
374
368
}
375
369
376
370
// Sets up a test environment and returns the runner struct
377
- func BeforeSuit (metrics []* backend.PodMetrics ) {
371
+ func BeforeSuit (metrics []* backend.Metrics ) [] * backend. PodMetrics {
378
372
// Set up mock k8s API Client
379
373
testEnv = & envtest.Environment {
380
374
CRDDirectoryPaths : []string {filepath .Join (".." , ".." , "config" , "crd" , "bases" )},
@@ -396,17 +390,21 @@ func BeforeSuit(metrics []*backend.PodMetrics) {
396
390
log .Fatalf ("No error, but returned kubernetes client is nil, cfg: %v" , cfg )
397
391
}
398
392
393
+ var podMetrics []* backend.PodMetrics
399
394
fakeLister := & testingutil.FakePodLister {
400
395
PodsList : []* corev1.Pod {},
401
396
}
402
397
for i , m := range metrics {
403
398
podName := "pod-" + strconv .Itoa (i )
404
399
pod := testingutil .MakePod (podName ).SetReady ().SetPodIP (podName ).Obj ()
405
400
fakeLister .PodsList = append (fakeLister .PodsList , pod )
406
- m .Pod = backend.Pod {
407
- Name : pod .Name ,
408
- Address : pod .Status .PodIP + ":8000" ,
409
- }
401
+ podMetrics = append (podMetrics , & backend.PodMetrics {
402
+ Pod : backend.Pod {
403
+ Name : pod .Name ,
404
+ Address : pod .Status .PodIP + ":8000" ,
405
+ },
406
+ Metrics : * m ,
407
+ })
410
408
}
411
409
412
410
serverRunner = runserver .NewDefaultExtProcServerRunner ()
@@ -431,6 +429,7 @@ func BeforeSuit(metrics []*backend.PodMetrics) {
431
429
432
430
// Wait the reconcilers to populate the datastore.
433
431
time .Sleep (5 * time .Second )
432
+ return podMetrics
434
433
}
435
434
436
435
func sendRequest (t * testing.T , client extProcPb.ExternalProcessor_ProcessClient , req * extProcPb.ProcessingRequest ) (* extProcPb.ProcessingResponse , error ) {
0 commit comments