@@ -1257,66 +1257,66 @@ func TestSchedulerCache_UpdateSnapshot(t *testing.T) {
1257
1257
1258
1258
var cache * schedulerCache
1259
1259
var snapshot * Snapshot
1260
- type operation = func ()
1260
+ type operation = func (t * testing. T )
1261
1261
1262
1262
addNode := func (i int ) operation {
1263
- return func () {
1263
+ return func (t * testing. T ) {
1264
1264
if err := cache .AddNode (nodes [i ]); err != nil {
1265
1265
t .Error (err )
1266
1266
}
1267
1267
}
1268
1268
}
1269
1269
removeNode := func (i int ) operation {
1270
- return func () {
1270
+ return func (t * testing. T ) {
1271
1271
if err := cache .RemoveNode (nodes [i ]); err != nil {
1272
1272
t .Error (err )
1273
1273
}
1274
1274
}
1275
1275
}
1276
1276
updateNode := func (i int ) operation {
1277
- return func () {
1277
+ return func (t * testing. T ) {
1278
1278
if err := cache .UpdateNode (nodes [i ], updatedNodes [i ]); err != nil {
1279
1279
t .Error (err )
1280
1280
}
1281
1281
}
1282
1282
}
1283
1283
addPod := func (i int ) operation {
1284
- return func () {
1284
+ return func (t * testing. T ) {
1285
1285
if err := cache .AddPod (pods [i ]); err != nil {
1286
1286
t .Error (err )
1287
1287
}
1288
1288
}
1289
1289
}
1290
1290
addPodWithAffinity := func (i int ) operation {
1291
- return func () {
1291
+ return func (t * testing. T ) {
1292
1292
if err := cache .AddPod (podsWithAffinity [i ]); err != nil {
1293
1293
t .Error (err )
1294
1294
}
1295
1295
}
1296
1296
}
1297
1297
removePod := func (i int ) operation {
1298
- return func () {
1298
+ return func (t * testing. T ) {
1299
1299
if err := cache .RemovePod (pods [i ]); err != nil {
1300
1300
t .Error (err )
1301
1301
}
1302
1302
}
1303
1303
}
1304
1304
removePodWithAffinity := func (i int ) operation {
1305
- return func () {
1305
+ return func (t * testing. T ) {
1306
1306
if err := cache .RemovePod (podsWithAffinity [i ]); err != nil {
1307
1307
t .Error (err )
1308
1308
}
1309
1309
}
1310
1310
}
1311
1311
updatePod := func (i int ) operation {
1312
- return func () {
1312
+ return func (t * testing. T ) {
1313
1313
if err := cache .UpdatePod (pods [i ], updatedPods [i ]); err != nil {
1314
1314
t .Error (err )
1315
1315
}
1316
1316
}
1317
1317
}
1318
1318
updateSnapshot := func () operation {
1319
- return func () {
1319
+ return func (t * testing. T ) {
1320
1320
cache .UpdateSnapshot (snapshot )
1321
1321
if err := compareCacheWithNodeInfoSnapshot (t , cache , snapshot ); err != nil {
1322
1322
t .Error (err )
@@ -1434,8 +1434,9 @@ func TestSchedulerCache_UpdateSnapshot(t *testing.T) {
1434
1434
{
1435
1435
name : "Remove node before its pods" ,
1436
1436
operations : []operation {
1437
- addNode (0 ), addNode (1 ), addPod (1 ), addPod (11 ),
1438
- removeNode (1 ), updatePod (1 ), updatePod (11 ), removePod (1 ), removePod (11 ),
1437
+ addNode (0 ), addNode (1 ), addPod (1 ), addPod (11 ), updateSnapshot (),
1438
+ removeNode (1 ), updateSnapshot (),
1439
+ updatePod (1 ), updatePod (11 ), removePod (1 ), removePod (11 ),
1439
1440
},
1440
1441
expected : []* v1.Node {nodes [0 ]},
1441
1442
},
@@ -1471,7 +1472,7 @@ func TestSchedulerCache_UpdateSnapshot(t *testing.T) {
1471
1472
snapshot = NewEmptySnapshot ()
1472
1473
1473
1474
for _ , op := range test .operations {
1474
- op ()
1475
+ op (t )
1475
1476
}
1476
1477
1477
1478
if len (test .expected ) != len (cache .nodes ) {
@@ -1508,18 +1509,22 @@ func TestSchedulerCache_UpdateSnapshot(t *testing.T) {
1508
1509
1509
1510
func compareCacheWithNodeInfoSnapshot (t * testing.T , cache * schedulerCache , snapshot * Snapshot ) error {
1510
1511
// Compare the map.
1511
- if len (snapshot .nodeInfoMap ) != len ( cache .nodes ) {
1512
- return fmt .Errorf ("unexpected number of nodes in the snapshot. Expected: %v, got: %v" , len ( cache .nodes ) , len (snapshot .nodeInfoMap ))
1512
+ if len (snapshot .nodeInfoMap ) != cache .nodeTree . numNodes {
1513
+ return fmt .Errorf ("unexpected number of nodes in the snapshot. Expected: %v, got: %v" , cache .nodeTree . numNodes , len (snapshot .nodeInfoMap ))
1513
1514
}
1514
1515
for name , ni := range cache .nodes {
1515
- if ! reflect .DeepEqual (snapshot .nodeInfoMap [name ], ni .info ) {
1516
- return fmt .Errorf ("unexpected node info for node %q. Expected: %v, got: %v" , name , ni .info , snapshot .nodeInfoMap [name ])
1516
+ want := ni .info
1517
+ if want .Node () == nil {
1518
+ want = nil
1519
+ }
1520
+ if ! reflect .DeepEqual (snapshot .nodeInfoMap [name ], want ) {
1521
+ return fmt .Errorf ("unexpected node info for node %q.Expected:\n %v, got:\n %v" , name , ni .info , snapshot .nodeInfoMap [name ])
1517
1522
}
1518
1523
}
1519
1524
1520
1525
// Compare the lists.
1521
- if len (snapshot .nodeInfoList ) != len ( cache .nodes ) {
1522
- return fmt .Errorf ("unexpected number of nodes in NodeInfoList. Expected: %v, got: %v" , len ( cache .nodes ) , len (snapshot .nodeInfoList ))
1526
+ if len (snapshot .nodeInfoList ) != cache .nodeTree . numNodes {
1527
+ return fmt .Errorf ("unexpected number of nodes in NodeInfoList. Expected: %v, got: %v" , cache .nodeTree . numNodes , len (snapshot .nodeInfoList ))
1523
1528
}
1524
1529
1525
1530
expectedNodeInfoList := make ([]* framework.NodeInfo , 0 , cache .nodeTree .numNodes )
0 commit comments