@@ -82,7 +82,7 @@ func TestPool(t *testing.T) {
82
82
fakeClient := fake .NewClientBuilder ().
83
83
WithScheme (scheme ).
84
84
Build ()
85
- pmf := backendmetrics .NewPodMetricsFactory (& backendmetrics.FakePodMetricsClient {}, time .Second , time . Second * 2 )
85
+ pmf := backendmetrics .NewPodMetricsFactory (& backendmetrics.FakePodMetricsClient {}, time .Second )
86
86
datastore := NewDatastore (context .Background (), pmf )
87
87
_ = datastore .PoolSet (context .Background (), fakeClient , tt .inferencePool )
88
88
gotPool , gotErr := datastore .PoolGet ()
@@ -189,7 +189,7 @@ func TestObjective(t *testing.T) {
189
189
}
190
190
for _ , test := range tests {
191
191
t .Run (test .name , func (t * testing.T ) {
192
- pmf := backendmetrics .NewPodMetricsFactory (& backendmetrics.FakePodMetricsClient {}, time .Second , time . Second * 2 )
192
+ pmf := backendmetrics .NewPodMetricsFactory (& backendmetrics.FakePodMetricsClient {}, time .Second )
193
193
ds := NewDatastore (t .Context (), pmf )
194
194
for _ , m := range test .existingModels {
195
195
ds .ObjectiveSet (m )
@@ -256,6 +256,7 @@ func TestMetrics(t *testing.T) {
256
256
pmc backendmetrics.PodMetricsClient
257
257
storePods []* corev1.Pod
258
258
want []* backendmetrics.MetricsState
259
+ predict func (backendmetrics.PodMetrics ) bool
259
260
}{
260
261
{
261
262
name : "Probing metrics success" ,
@@ -313,15 +314,18 @@ func TestMetrics(t *testing.T) {
313
314
fakeClient := fake .NewClientBuilder ().
314
315
WithScheme (scheme ).
315
316
Build ()
316
- pmf := backendmetrics .NewPodMetricsFactory (test .pmc , time .Millisecond , time . Second * 2 )
317
+ pmf := backendmetrics .NewPodMetricsFactory (test .pmc , time .Millisecond )
317
318
ds := NewDatastore (ctx , pmf )
318
319
_ = ds .PoolSet (ctx , fakeClient , inferencePool )
319
320
for _ , pod := range test .storePods {
320
321
ds .PodUpdateOrAddIfNotExist (pod )
321
322
}
322
323
time .Sleep (1 * time .Second ) // Give some time for the metrics to be fetched.
324
+ if test .predict == nil {
325
+ test .predict = backendmetrics .AllPodsPredicate
326
+ }
323
327
assert .EventuallyWithT (t , func (t * assert.CollectT ) {
324
- got := ds .PodList (backendmetrics . AllPodPredicate )
328
+ got := ds .PodList (test . predict )
325
329
metrics := []* backendmetrics.MetricsState {}
326
330
for _ , one := range got {
327
331
metrics = append (metrics , one .GetMetrics ())
@@ -407,15 +411,15 @@ func TestPods(t *testing.T) {
407
411
for _ , test := range tests {
408
412
t .Run (test .name , func (t * testing.T ) {
409
413
ctx := context .Background ()
410
- pmf := backendmetrics .NewPodMetricsFactory (& backendmetrics.FakePodMetricsClient {}, time .Second , time . Second * 2 )
414
+ pmf := backendmetrics .NewPodMetricsFactory (& backendmetrics.FakePodMetricsClient {}, time .Second )
411
415
ds := NewDatastore (t .Context (), pmf )
412
416
for _ , pod := range test .existingPods {
413
417
ds .PodUpdateOrAddIfNotExist (pod )
414
418
}
415
419
416
420
test .op (ctx , ds )
417
421
var gotPods []* corev1.Pod
418
- for _ , pm := range ds .PodList (backendmetrics .AllPodPredicate ) {
422
+ for _ , pm := range ds .PodList (backendmetrics .AllPodsPredicate ) {
419
423
pod := & corev1.Pod {ObjectMeta : metav1.ObjectMeta {Name : pm .GetPod ().NamespacedName .Name , Namespace : pm .GetPod ().NamespacedName .Namespace }, Status : corev1.PodStatus {PodIP : pm .GetPod ().Address }}
420
424
gotPods = append (gotPods , pod )
421
425
}
0 commit comments