@@ -19,6 +19,7 @@ package requestcontrol
19
19
import (
20
20
"context"
21
21
"errors"
22
+ "fmt"
22
23
"testing"
23
24
"time"
24
25
@@ -29,7 +30,6 @@ import (
29
30
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30
31
"k8s.io/apimachinery/pkg/runtime"
31
32
"k8s.io/apimachinery/pkg/types"
32
- k8stypes "k8s.io/apimachinery/pkg/types"
33
33
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
34
34
"sigs.k8s.io/controller-runtime/pkg/client/fake"
35
35
@@ -109,26 +109,29 @@ func TestDirector_HandleRequest(t *testing.T) {
109
109
},
110
110
}
111
111
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
- }
125
112
scheme := runtime .NewScheme ()
126
113
_ = clientgoscheme .AddToScheme (scheme )
127
114
fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).Build ()
128
115
if err := ds .PoolSet (ctx , fakeClient , pool ); err != nil {
129
116
t .Fatalf ("Error while setting inference pool: %v" , err )
130
117
}
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
+ }
132
135
133
136
defaultSuccessfulScheduleResults := & schedulingtypes.SchedulingResult {
134
137
ProfileResults : map [string ]* schedulingtypes.ProfileRunResult {
@@ -138,7 +141,23 @@ func TestDirector_HandleRequest(t *testing.T) {
138
141
Pod : & schedulingtypes.PodMetrics {
139
142
Pod : & backend.Pod {
140
143
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" },
142
161
},
143
162
},
144
163
},
@@ -174,7 +193,7 @@ func TestDirector_HandleRequest(t *testing.T) {
174
193
NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
175
194
Address : "192.168.1.100" ,
176
195
},
177
- TargetEndpoint : "192.168.1.100:8000" ,
196
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
178
197
},
179
198
wantMutatedBodyModel : model ,
180
199
},
@@ -199,7 +218,7 @@ func TestDirector_HandleRequest(t *testing.T) {
199
218
NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
200
219
Address : "192.168.1.100" ,
201
220
},
202
- TargetEndpoint : "192.168.1.100:8000" ,
221
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
203
222
},
204
223
wantMutatedBodyModel : model ,
205
224
},
@@ -228,7 +247,7 @@ func TestDirector_HandleRequest(t *testing.T) {
228
247
NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
229
248
Address : "192.168.1.100" ,
230
249
},
231
- TargetEndpoint : "192.168.1.100:8000" ,
250
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
232
251
},
233
252
wantMutatedBodyModel : model ,
234
253
},
@@ -249,7 +268,7 @@ func TestDirector_HandleRequest(t *testing.T) {
249
268
NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
250
269
Address : "192.168.1.100" ,
251
270
},
252
- TargetEndpoint : "192.168.1.100:8000" ,
271
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
253
272
},
254
273
wantMutatedBodyModel : modelSheddable ,
255
274
},
@@ -270,7 +289,7 @@ func TestDirector_HandleRequest(t *testing.T) {
270
289
NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
271
290
Address : "192.168.1.100" ,
272
291
},
273
- TargetEndpoint : "192.168.1.100:8000" ,
292
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
274
293
},
275
294
wantMutatedBodyModel : "resolved-target-model-A" ,
276
295
},
@@ -286,7 +305,7 @@ func TestDirector_HandleRequest(t *testing.T) {
286
305
NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
287
306
Address : "192.168.1.100" ,
288
307
},
289
- TargetEndpoint : "192.168.1.100:8000" ,
308
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
290
309
},
291
310
wantMutatedBodyModel : "food-review-1" ,
292
311
reqBodyMap : map [string ]any {
0 commit comments