@@ -19,6 +19,7 @@ package requestcontrol
1919import (
2020 "context"
2121 "errors"
22+ "fmt"
2223 "testing"
2324 "time"
2425
@@ -29,7 +30,6 @@ import (
2930 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031 "k8s.io/apimachinery/pkg/runtime"
3132 "k8s.io/apimachinery/pkg/types"
32- k8stypes "k8s.io/apimachinery/pkg/types"
3333 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3434 "sigs.k8s.io/controller-runtime/pkg/client/fake"
3535
@@ -109,26 +109,29 @@ func TestDirector_HandleRequest(t *testing.T) {
109109 },
110110 }
111111
112- // Pod setup
113- testPod := & corev1.Pod {
114- ObjectMeta : metav1.ObjectMeta {
115- Name : "pod1" ,
116- Namespace : "default" ,
117- Labels : map [string ]string {"app" : "inference" },
118- },
119- Status : corev1.PodStatus {
120- PodIP : "192.168.1.100" ,
121- Phase : corev1 .PodRunning ,
122- Conditions : []corev1.PodCondition {{Type : corev1 .PodReady , Status : corev1 .ConditionTrue }},
123- },
124- }
125112 scheme := runtime .NewScheme ()
126113 _ = clientgoscheme .AddToScheme (scheme )
127114 fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).Build ()
128115 if err := ds .PoolSet (ctx , fakeClient , pool ); err != nil {
129116 t .Fatalf ("Error while setting inference pool: %v" , err )
130117 }
131- ds .PodUpdateOrAddIfNotExist (testPod )
118+
119+ for i := range 5 {
120+ // Pod setup
121+ testPod := & corev1.Pod {
122+ ObjectMeta : metav1.ObjectMeta {
123+ Name : fmt .Sprintf ("pod%v" , i + 1 ),
124+ Namespace : "default" ,
125+ Labels : map [string ]string {"app" : "inference" },
126+ },
127+ Status : corev1.PodStatus {
128+ PodIP : fmt .Sprintf ("192.168.%v.100" , i + 1 ),
129+ Phase : corev1 .PodRunning ,
130+ Conditions : []corev1.PodCondition {{Type : corev1 .PodReady , Status : corev1 .ConditionTrue }},
131+ },
132+ }
133+ ds .PodUpdateOrAddIfNotExist (testPod )
134+ }
132135
133136 defaultSuccessfulScheduleResults := & schedulingtypes.SchedulingResult {
134137 ProfileResults : map [string ]* schedulingtypes.ProfileRunResult {
@@ -138,7 +141,23 @@ func TestDirector_HandleRequest(t *testing.T) {
138141 Pod : & schedulingtypes.PodMetrics {
139142 Pod : & backend.Pod {
140143 Address : "192.168.1.100" ,
141- NamespacedName : k8stypes.NamespacedName {Name : "pod1" , Namespace : "default" },
144+ NamespacedName : types.NamespacedName {Name : "pod1" , Namespace : "default" },
145+ },
146+ },
147+ },
148+ & schedulingtypes.ScoredPod {
149+ Pod : & schedulingtypes.PodMetrics {
150+ Pod : & backend.Pod {
151+ Address : "192.168.2.100" ,
152+ NamespacedName : types.NamespacedName {Name : "pod2" , Namespace : "default" },
153+ },
154+ },
155+ },
156+ & schedulingtypes.ScoredPod {
157+ Pod : & schedulingtypes.PodMetrics {
158+ Pod : & backend.Pod {
159+ Address : "192.168.4.100" ,
160+ NamespacedName : types.NamespacedName {Name : "pod4" , Namespace : "default" },
142161 },
143162 },
144163 },
@@ -174,7 +193,7 @@ func TestDirector_HandleRequest(t *testing.T) {
174193 NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
175194 Address : "192.168.1.100" ,
176195 },
177- TargetEndpoint : "192.168.1.100:8000" ,
196+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
178197 },
179198 wantMutatedBodyModel : model ,
180199 },
@@ -199,7 +218,7 @@ func TestDirector_HandleRequest(t *testing.T) {
199218 NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
200219 Address : "192.168.1.100" ,
201220 },
202- TargetEndpoint : "192.168.1.100:8000" ,
221+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
203222 },
204223 wantMutatedBodyModel : model ,
205224 },
@@ -228,7 +247,7 @@ func TestDirector_HandleRequest(t *testing.T) {
228247 NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
229248 Address : "192.168.1.100" ,
230249 },
231- TargetEndpoint : "192.168.1.100:8000" ,
250+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
232251 },
233252 wantMutatedBodyModel : model ,
234253 },
@@ -249,7 +268,7 @@ func TestDirector_HandleRequest(t *testing.T) {
249268 NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
250269 Address : "192.168.1.100" ,
251270 },
252- TargetEndpoint : "192.168.1.100:8000" ,
271+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
253272 },
254273 wantMutatedBodyModel : modelSheddable ,
255274 },
@@ -270,7 +289,7 @@ func TestDirector_HandleRequest(t *testing.T) {
270289 NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
271290 Address : "192.168.1.100" ,
272291 },
273- TargetEndpoint : "192.168.1.100:8000" ,
292+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
274293 },
275294 wantMutatedBodyModel : "resolved-target-model-A" ,
276295 },
@@ -286,7 +305,7 @@ func TestDirector_HandleRequest(t *testing.T) {
286305 NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
287306 Address : "192.168.1.100" ,
288307 },
289- TargetEndpoint : "192.168.1.100:8000" ,
308+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
290309 },
291310 wantMutatedBodyModel : "food-review-1" ,
292311 reqBodyMap : map [string ]any {
0 commit comments