@@ -125,139 +125,6 @@ func buildOwnerReference(owner string) metav1.OwnerReference {
125
125
}
126
126
}
127
127
128
- func TestAddPod (t * testing.T ) {
129
-
130
- owner := buildOwnerReference ("j1" )
131
-
132
- // case 1:
133
- pod1 := buildPod ("c1" , "p1" , "" , v1 .PodPending , buildResourceList ("1000m" , "1G" ),
134
- []metav1.OwnerReference {owner }, make (map [string ]string ))
135
- pi1 := api .NewTaskInfo (pod1 )
136
- pi1 .Job = "j1" // The job name is set by cache.
137
- pod2 := buildPod ("c1" , "p2" , "n1" , v1 .PodRunning , buildResourceList ("1000m" , "1G" ),
138
- []metav1.OwnerReference {owner }, make (map [string ]string ))
139
- pi2 := api .NewTaskInfo (pod2 )
140
- pi2 .Job = "j1" // The job name is set by cache.
141
-
142
- j1 := api .NewJobInfo (api .JobID ("j1" ), pi1 , pi2 )
143
- pg := createShadowPodGroup (pod1 )
144
- j1 .SetPodGroup (pg )
145
-
146
- node1 := buildNode ("n1" , buildResourceList ("2000m" , "10G" ))
147
- ni1 := api .NewNodeInfo (node1 )
148
- ni1 .AddTask (pi2 )
149
-
150
- tests := []struct {
151
- pods []* v1.Pod
152
- nodes []* v1.Node
153
- expected * SchedulerCache
154
- }{
155
- {
156
- pods : []* v1.Pod {pod1 , pod2 },
157
- nodes : []* v1.Node {node1 },
158
- expected : & SchedulerCache {
159
- Nodes : map [string ]* api.NodeInfo {
160
- "n1" : ni1 ,
161
- },
162
- Jobs : map [api.JobID ]* api.JobInfo {
163
- "j1" : j1 ,
164
- },
165
- },
166
- },
167
- }
168
-
169
- for i , test := range tests {
170
- cache := & SchedulerCache {
171
- Jobs : make (map [api.JobID ]* api.JobInfo ),
172
- Nodes : make (map [string ]* api.NodeInfo ),
173
- }
174
-
175
- for _ , n := range test .nodes {
176
- cache .AddNode (n )
177
- }
178
-
179
- for _ , p := range test .pods {
180
- cache .AddPod (p )
181
- }
182
-
183
- if ! cacheEqual (cache , test .expected ) {
184
- t .Errorf ("case %d: \n expected %v, \n got %v \n " ,
185
- i , test .expected , cache )
186
- }
187
- }
188
- }
189
-
190
- func TestAddNode (t * testing.T ) {
191
- owner1 := buildOwnerReference ("j1" )
192
- owner2 := buildOwnerReference ("j2" )
193
-
194
- // case 1
195
- node1 := buildNode ("n1" , buildResourceList ("2000m" , "10G" ))
196
- pod1 := buildPod ("c1" , "p1" , "" , v1 .PodPending , buildResourceList ("1000m" , "1G" ),
197
- []metav1.OwnerReference {owner1 }, make (map [string ]string ))
198
- pi1 := api .NewTaskInfo (pod1 )
199
- pi1 .Job = "j1" // The job name is set by cache.
200
-
201
- pod2 := buildPod ("c1" , "p2" , "n1" , v1 .PodRunning , buildResourceList ("1000m" , "1G" ),
202
- []metav1.OwnerReference {owner2 }, make (map [string ]string ))
203
- pi2 := api .NewTaskInfo (pod2 )
204
- pi2 .Job = "j2" // The job name is set by cache.
205
-
206
- ni1 := api .NewNodeInfo (node1 )
207
- ni1 .AddTask (pi2 )
208
-
209
- j1 := api .NewJobInfo ("j1" )
210
- pg1 := createShadowPodGroup (pod1 )
211
- j1 .SetPodGroup (pg1 )
212
-
213
- j2 := api .NewJobInfo ("j2" )
214
- pg2 := createShadowPodGroup (pod2 )
215
- j2 .SetPodGroup (pg2 )
216
-
217
- j1 .AddTaskInfo (pi1 )
218
- j2 .AddTaskInfo (pi2 )
219
-
220
- tests := []struct {
221
- pods []* v1.Pod
222
- nodes []* v1.Node
223
- expected * SchedulerCache
224
- }{
225
- {
226
- pods : []* v1.Pod {pod1 , pod2 },
227
- nodes : []* v1.Node {node1 },
228
- expected : & SchedulerCache {
229
- Nodes : map [string ]* api.NodeInfo {
230
- "n1" : ni1 ,
231
- },
232
- Jobs : map [api.JobID ]* api.JobInfo {
233
- "j1" : j1 ,
234
- "j2" : j2 ,
235
- },
236
- },
237
- },
238
- }
239
-
240
- for i , test := range tests {
241
- cache := & SchedulerCache {
242
- Nodes : make (map [string ]* api.NodeInfo ),
243
- Jobs : make (map [api.JobID ]* api.JobInfo ),
244
- }
245
-
246
- for _ , p := range test .pods {
247
- cache .AddPod (p )
248
- }
249
-
250
- for _ , n := range test .nodes {
251
- cache .AddNode (n )
252
- }
253
-
254
- if ! cacheEqual (cache , test .expected ) {
255
- t .Errorf ("case %d: \n expected %v, \n got %v \n " ,
256
- i , test .expected , cache )
257
- }
258
- }
259
- }
260
-
261
128
func TestGetOrCreateJob (t * testing.T ) {
262
129
owner1 := buildOwnerReference ("j1" )
263
130
owner2 := buildOwnerReference ("j2" )
@@ -292,7 +159,7 @@ func TestGetOrCreateJob(t *testing.T) {
292
159
},
293
160
{
294
161
task : pi2 ,
295
- gotJob : true ,
162
+ gotJob : false ,
296
163
},
297
164
{
298
165
task : pi3 ,
0 commit comments