@@ -81,7 +81,7 @@ func TestCreateWorkload(t *testing.T) {
81
81
}
82
82
83
83
func TestCreateWorkloadTxn (t * testing.T ) {
84
- c := NewTestCluster ( )
84
+ c , nodes := newCreateWorkloadCluster ( t )
85
85
ctx := context .Background ()
86
86
opts := & types.DeployOptions {
87
87
Name : "zc:name" ,
@@ -94,69 +94,12 @@ func TestCreateWorkloadTxn(t *testing.T) {
94
94
Name : "good-entrypoint" ,
95
95
},
96
96
}
97
- store := & storemocks.Store {}
98
- sche := & schedulermocks.Scheduler {}
99
- scheduler .InitSchedulerV1 (sche )
100
- c .store = store
101
- c .scheduler = sche
102
- engine := & enginemocks.API {}
103
-
104
- pod1 := & types.Pod {Name : "p1" }
105
- node1 := & types.Node {
106
- NodeMeta : types.NodeMeta {
107
- Name : "n1" ,
108
- },
109
- Engine : engine ,
110
- }
111
- node2 := & types.Node {
112
- NodeMeta : types.NodeMeta {
113
- Name : "n2" ,
114
- },
115
- Engine : engine ,
116
- }
117
- nodes := []* types.Node {node1 , node2 }
118
-
119
- store .On ("SaveProcessing" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
120
- store .On ("UpdateProcessing" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
121
- store .On ("DeleteProcessing" , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
122
97
123
- // doAllocResource fails: MakeDeployStatus
124
- lock := & lockmocks.DistributedLock {}
125
- lock .On ("Lock" , mock .Anything ).Return (context .Background (), nil )
126
- lock .On ("Unlock" , mock .Anything ).Return (nil )
127
- store .On ("CreateLock" , mock .Anything , mock .Anything ).Return (lock , nil )
128
- store .On ("GetPod" , mock .Anything , mock .Anything ).Return (pod1 , nil )
129
- store .On ("GetNodesByPod" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nodes , nil )
130
- store .On ("GetNode" ,
131
- mock .AnythingOfType ("*context.emptyCtx" ),
132
- mock .AnythingOfType ("string" ),
133
- ).Return (
134
- func (_ context.Context , name string ) (node * types.Node ) {
135
- node = node1
136
- if name == "n2" {
137
- node = node2
138
- }
139
- return
140
- }, nil )
141
- sche .On ("SelectStorageNodes" , mock .AnythingOfType ("[]resourcetypes.ScheduleInfo" ), mock .AnythingOfType ("int64" )).Return (func (scheduleInfos []resourcetypes.ScheduleInfo , _ int64 ) []resourcetypes.ScheduleInfo {
142
- return scheduleInfos
143
- }, len (nodes ), nil )
144
- sche .On ("SelectStorageNodes" , mock .AnythingOfType ("[]types.ScheduleInfo" ), mock .AnythingOfType ("int64" )).Return (func (scheduleInfos []resourcetypes.ScheduleInfo , _ int64 ) []resourcetypes.ScheduleInfo {
145
- return scheduleInfos
146
- }, len (nodes ), nil )
147
- sche .On ("SelectVolumeNodes" , mock .AnythingOfType ("[]types.ScheduleInfo" ), mock .AnythingOfType ("types.VolumeBindings" )).Return (func (scheduleInfos []resourcetypes.ScheduleInfo , _ types.VolumeBindings ) []resourcetypes.ScheduleInfo {
148
- return scheduleInfos
149
- }, nil , len (nodes ), nil )
150
- sche .On ("SelectMemoryNodes" , mock .AnythingOfType ("[]types.ScheduleInfo" ), mock .AnythingOfType ("float64" ), mock .AnythingOfType ("int64" )).Return (
151
- func (scheduleInfos []resourcetypes.ScheduleInfo , _ float64 , _ int64 ) []resourcetypes.ScheduleInfo {
152
- for i := range scheduleInfos {
153
- scheduleInfos [i ].Capacity = 1
154
- }
155
- return scheduleInfos
156
- }, len (nodes ), nil )
98
+ store := c .store .(* storemocks.Store )
157
99
store .On ("MakeDeployStatus" , mock .Anything , mock .Anything , mock .Anything ).Return (
158
100
errors .Wrap (context .DeadlineExceeded , "MakeDeployStatus" ),
159
101
).Once ()
102
+
160
103
ch , err := c .CreateWorkload (ctx , opts )
161
104
assert .Nil (t , err )
162
105
cnt := 0
@@ -168,7 +111,6 @@ func TestCreateWorkloadTxn(t *testing.T) {
168
111
assert .EqualValues (t , 1 , cnt )
169
112
170
113
// commit resource changes fails: UpdateNodes
171
- store .On ("GetNodesByPod" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nodes , nil )
172
114
store .On ("MakeDeployStatus" , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
173
115
old := strategy .Plans [strategy .Auto ]
174
116
strategy .Plans [strategy .Auto ] = func (sis []strategy.Info , need , total , _ int ) (map [string ]int , error ) {
@@ -191,6 +133,7 @@ func TestCreateWorkloadTxn(t *testing.T) {
191
133
assert .Error (t , m .Error , "UpdateNodes1" )
192
134
}
193
135
assert .EqualValues (t , 1 , cnt )
136
+ node1 , node2 := nodes [0 ], nodes [1 ]
194
137
assert .EqualValues (t , 1 , node1 .CPUUsed )
195
138
assert .EqualValues (t , 1 , node2 .CPUUsed )
196
139
node1 .CPUUsed = 0
@@ -221,6 +164,7 @@ func TestCreateWorkloadTxn(t *testing.T) {
221
164
}
222
165
return
223
166
}, nil )
167
+ engine := node1 .Engine .(* enginemocks.API )
224
168
engine .On ("ImageLocalDigests" , mock .Anything , mock .Anything ).Return (nil , errors .Wrap (context .DeadlineExceeded , "ImageLocalDigest" )).Twice ()
225
169
engine .On ("ImagePull" , mock .Anything , mock .Anything , mock .Anything ).Return (nil , errors .Wrap (context .DeadlineExceeded , "ImagePull" )).Twice ()
226
170
store .On ("UpdateProcessing" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
@@ -299,3 +243,70 @@ func TestCreateWorkloadTxn(t *testing.T) {
299
243
assert .EqualValues (t , 1 , node1 .CPUUsed + node2 .CPUUsed )
300
244
return
301
245
}
246
+
247
+ func newCreateWorkloadCluster (t * testing.T ) (* Calcium , []* types.Node ) {
248
+ c := NewTestCluster ()
249
+ c .store = & storemocks.Store {}
250
+ c .scheduler = & schedulermocks.Scheduler {}
251
+ scheduler .InitSchedulerV1 (c .scheduler )
252
+
253
+ engine := & enginemocks.API {}
254
+ pod1 := & types.Pod {Name : "p1" }
255
+ node1 := & types.Node {
256
+ NodeMeta : types.NodeMeta {
257
+ Name : "n1" ,
258
+ },
259
+ Engine : engine ,
260
+ }
261
+ node2 := & types.Node {
262
+ NodeMeta : types.NodeMeta {
263
+ Name : "n2" ,
264
+ },
265
+ Engine : engine ,
266
+ }
267
+ nodes := []* types.Node {node1 , node2 }
268
+
269
+ store := c .store .(* storemocks.Store )
270
+ store .On ("SaveProcessing" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
271
+ store .On ("UpdateProcessing" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
272
+ store .On ("DeleteProcessing" , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
273
+
274
+ // doAllocResource fails: MakeDeployStatus
275
+ lock := & lockmocks.DistributedLock {}
276
+ lock .On ("Lock" , mock .Anything ).Return (context .Background (), nil )
277
+ lock .On ("Unlock" , mock .Anything ).Return (nil )
278
+ store .On ("CreateLock" , mock .Anything , mock .Anything ).Return (lock , nil )
279
+ store .On ("GetPod" , mock .Anything , mock .Anything ).Return (pod1 , nil )
280
+ store .On ("GetNodesByPod" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nodes , nil )
281
+ store .On ("GetNode" ,
282
+ mock .AnythingOfType ("*context.emptyCtx" ),
283
+ mock .AnythingOfType ("string" ),
284
+ ).Return (
285
+ func (_ context.Context , name string ) (node * types.Node ) {
286
+ node = node1
287
+ if name == "n2" {
288
+ node = node2
289
+ }
290
+ return
291
+ }, nil )
292
+
293
+ sche := c .scheduler .(* schedulermocks.Scheduler )
294
+ sche .On ("SelectStorageNodes" , mock .AnythingOfType ("[]resourcetypes.ScheduleInfo" ), mock .AnythingOfType ("int64" )).Return (func (scheduleInfos []resourcetypes.ScheduleInfo , _ int64 ) []resourcetypes.ScheduleInfo {
295
+ return scheduleInfos
296
+ }, len (nodes ), nil )
297
+ sche .On ("SelectStorageNodes" , mock .AnythingOfType ("[]types.ScheduleInfo" ), mock .AnythingOfType ("int64" )).Return (func (scheduleInfos []resourcetypes.ScheduleInfo , _ int64 ) []resourcetypes.ScheduleInfo {
298
+ return scheduleInfos
299
+ }, len (nodes ), nil )
300
+ sche .On ("SelectVolumeNodes" , mock .AnythingOfType ("[]types.ScheduleInfo" ), mock .AnythingOfType ("types.VolumeBindings" )).Return (func (scheduleInfos []resourcetypes.ScheduleInfo , _ types.VolumeBindings ) []resourcetypes.ScheduleInfo {
301
+ return scheduleInfos
302
+ }, nil , len (nodes ), nil )
303
+ sche .On ("SelectMemoryNodes" , mock .AnythingOfType ("[]types.ScheduleInfo" ), mock .AnythingOfType ("float64" ), mock .AnythingOfType ("int64" )).Return (
304
+ func (scheduleInfos []resourcetypes.ScheduleInfo , _ float64 , _ int64 ) []resourcetypes.ScheduleInfo {
305
+ for i := range scheduleInfos {
306
+ scheduleInfos [i ].Capacity = 1
307
+ }
308
+ return scheduleInfos
309
+ }, len (nodes ), nil )
310
+
311
+ return c , nodes
312
+ }
0 commit comments