@@ -285,14 +285,11 @@ func TestReallocBindCpu(t *testing.T) {
285
285
ctx := context .Background ()
286
286
store := & storemocks.Store {}
287
287
c .store = store
288
- pod1 := & types.Pod {
289
- Name : "p1" ,
290
- }
288
+
291
289
lock := & lockmocks.DistributedLock {}
292
290
lock .On ("Lock" , mock .Anything ).Return (context .TODO (), nil )
293
291
lock .On ("Unlock" , mock .Anything ).Return (nil )
294
292
store .On ("CreateLock" , mock .Anything , mock .Anything ).Return (lock , nil )
295
- store .On ("GetPod" , mock .Anything , mock .Anything ).Return (pod1 , nil )
296
293
engine := & enginemocks.API {}
297
294
engine .On ("VirtualizationInspect" , mock .Anything , mock .Anything ).Return (& enginetypes.VirtualizationInfo {}, nil )
298
295
@@ -361,32 +358,34 @@ func TestReallocBindCpu(t *testing.T) {
361
358
362
359
store .On ("GetNode" , mock .Anything , "node3" ).Return (node3 , nil )
363
360
store .On ("GetWorkloads" , mock .Anything , []string {"c5" }).Return ([]* types.Workload {c5 }, nil )
364
- store .On ("GetWorkloads" , mock .Anything , []string {"c6" }).Return ([]* types.Workload {c6 }, nil )
365
- store .On ("GetWorkloads" , mock .Anything , []string {"c6" , "c5" }).Return ([]* types.Workload {c5 , c6 }, nil )
366
361
engine .On ("VirtualizationUpdateResource" , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
367
362
store .On ("UpdateWorkload" , mock .Anything , mock .Anything ).Return (nil )
368
363
369
364
// failed by UpdateNodes
370
365
store .On ("UpdateNodes" , mock .Anything , mock .Anything ).Return (types .ErrBadWorkloadID ).Once ()
371
366
err := c .ReallocResource (ctx , newReallocOptions ("c5" , 0.1 , 2 * int64 (units .MiB ), nil , types .TriFalse , types .TriKeep ))
372
367
assert .Error (t , err )
373
- store .On ( "UpdateNodes" , mock . Anything , mock . Anything ). Return ( nil )
368
+ store .AssertExpectations ( t )
374
369
370
+ store .On ("ListNodeWorkloads" , mock .Anything , mock .Anything , mock .Anything ).Return (nil , types .ErrNoETCD )
371
+ store .On ("UpdateNodes" , mock .Anything , mock .Anything ).Return (nil )
375
372
err = c .ReallocResource (ctx , newReallocOptions ("c5" , 0.1 , 2 * int64 (units .MiB ), nil , types .TriFalse , types .TriKeep ))
376
373
assert .NoError (t , err )
377
374
assert .Equal (t , 0 , len (c5 .ResourceMeta .CPU ))
375
+ store .AssertExpectations (t )
378
376
377
+ store .On ("GetWorkloads" , mock .Anything , []string {"c6" }).Return ([]* types.Workload {c6 }, nil )
379
378
err = c .ReallocResource (ctx , newReallocOptions ("c6" , 0.1 , 2 * int64 (units .MiB ), nil , types .TriTrue , types .TriKeep ))
380
379
assert .NoError (t , err )
381
380
assert .NotEmpty (t , c6 .ResourceMeta .CPU )
381
+ store .AssertExpectations (t )
382
382
383
383
node3 .CPU = types.CPUMap {"0" : 10 , "1" : 70 , "2" : 100 , "3" : 100 }
384
384
err = c .ReallocResource (ctx , newReallocOptions ("c5" , - 0.1 , 2 * int64 (units .MiB ), nil , types .TriTrue , types .TriKeep ))
385
-
386
385
assert .NoError (t , err )
387
386
assert .NotEmpty (t , c5 .ResourceMeta .CPU )
388
387
err = c .ReallocResource (ctx , newReallocOptions ("c6" , - 0.1 , 2 * int64 (units .MiB ), nil , types .TriFalse , types .TriKeep ))
389
-
390
388
assert .NoError (t , err )
391
389
assert .Equal (t , 0 , len (c6 .ResourceMeta .CPU ))
390
+ store .AssertExpectations (t )
392
391
}
0 commit comments