@@ -1386,13 +1386,9 @@ func TestNeedsCleanup(t *testing.T) {
1386
1386
// make sure that the slow node sync never removes the Node from LB set because it
1387
1387
// has stale data.
1388
1388
func TestSlowNodeSync (t * testing.T ) {
1389
- stopCh , updateCallCh := make (chan struct {}), make (chan fakecloud. UpdateBalancerCall )
1389
+ stopCh , syncServiceDone , syncService := make (chan struct {}), make (chan string ), make ( chan string )
1390
1390
defer close (stopCh )
1391
- defer close (updateCallCh )
1392
-
1393
- duration := time .Millisecond
1394
-
1395
- syncService := make (chan string )
1391
+ defer close (syncService )
1396
1392
1397
1393
node1 := makeNode (tweakName ("node1" ))
1398
1394
node2 := makeNode (tweakName ("node2" ))
@@ -1405,14 +1401,16 @@ func TestSlowNodeSync(t *testing.T) {
1405
1401
serviceKeys := sets .New (sKey1 , sKey2 )
1406
1402
1407
1403
controller , cloudProvider , kubeClient := newController (stopCh , node1 , node2 , service1 , service2 )
1408
- cloudProvider .RequestDelay = 4 * duration
1409
1404
cloudProvider .UpdateCallCb = func (update fakecloud.UpdateBalancerCall ) {
1410
- updateCallCh <- update
1405
+ key , _ := cache .MetaNamespaceKeyFunc (update .Service )
1406
+ impactedService := serviceKeys .Difference (sets .New (key )).UnsortedList ()[0 ]
1407
+ syncService <- impactedService
1408
+ <- syncServiceDone
1409
+
1411
1410
}
1412
1411
cloudProvider .EnsureCallCb = func (update fakecloud.UpdateBalancerCall ) {
1413
- updateCallCh <- update
1412
+ syncServiceDone <- update . Service . Name
1414
1413
}
1415
-
1416
1414
// Two update calls are expected. This is because this test calls
1417
1415
// controller.syncNodes once with two existing services, but with one
1418
1416
// controller.syncService while that is happening. The end result is
@@ -1428,6 +1426,8 @@ func TestSlowNodeSync(t *testing.T) {
1428
1426
expectedUpdateCalls := []fakecloud.UpdateBalancerCall {
1429
1427
// First update call for first service from controller.syncNodes
1430
1428
{Service : service1 , Hosts : []* v1.Node {node1 , node2 }},
1429
+ }
1430
+ expectedEnsureCalls := []fakecloud.UpdateBalancerCall {
1431
1431
// Second update call for impacted service from controller.syncService
1432
1432
{Service : service2 , Hosts : []* v1.Node {node1 , node2 , node3 }},
1433
1433
}
@@ -1439,51 +1439,34 @@ func TestSlowNodeSync(t *testing.T) {
1439
1439
controller .syncNodes (context .TODO (), 1 )
1440
1440
}()
1441
1441
1442
- wg .Add (1 )
1443
- go func () {
1444
- defer wg .Done ()
1445
- updateCallIdx := 0
1446
- impactedService := ""
1447
- for update := range updateCallCh {
1448
- // Validate that the call hosts are what we expect
1449
- if ! compareHostSets (t , expectedUpdateCalls [updateCallIdx ].Hosts , update .Hosts ) {
1450
- t .Errorf ("unexpected updated hosts for update: %v, expected: %v, got: %v" , updateCallIdx , expectedUpdateCalls [updateCallIdx ].Hosts , update .Hosts )
1451
- return
1452
- }
1453
- key , _ := cache .MetaNamespaceKeyFunc (update .Service )
1454
- // For call 0: determine impacted service
1455
- if updateCallIdx == 0 {
1456
- impactedService = serviceKeys .Difference (sets .New (key )).UnsortedList ()[0 ]
1457
- syncService <- impactedService
1458
- }
1459
- // For calls > 0: validate the impacted service
1460
- if updateCallIdx > 0 {
1461
- if key != impactedService {
1462
- t .Error ("unexpected impacted service" )
1463
- return
1464
- }
1465
- }
1466
- if updateCallIdx == len (expectedUpdateCalls )- 1 {
1467
- return
1468
- }
1469
- updateCallIdx ++
1470
- }
1471
- }()
1472
-
1473
1442
key := <- syncService
1474
1443
if _ , err := kubeClient .CoreV1 ().Nodes ().Create (context .TODO (), node3 , metav1.CreateOptions {}); err != nil {
1475
1444
t .Fatalf ("error creating node3, err: %v" , err )
1476
1445
}
1477
1446
1478
- // Give it some time to update the informer cache, needs to be lower than
1479
- // cloudProvider.RequestDelay
1480
- time .Sleep (duration )
1481
1447
// Sync the service
1482
1448
if err := controller .syncService (context .TODO (), key ); err != nil {
1483
- t .Errorf ("unexpected service sync error, err: %v" , err )
1449
+ t .Fatalf ("unexpected service sync error, err: %v" , err )
1484
1450
}
1485
1451
1486
1452
wg .Wait ()
1453
+
1454
+ if len (expectedUpdateCalls ) != len (cloudProvider .UpdateCalls ) {
1455
+ t .Fatalf ("unexpected amount of update calls, expected: %v, got: %v" , len (expectedUpdateCalls ), len (cloudProvider .UpdateCalls ))
1456
+ }
1457
+ for idx , update := range cloudProvider .UpdateCalls {
1458
+ if ! compareHostSets (t , expectedUpdateCalls [idx ].Hosts , update .Hosts ) {
1459
+ t .Fatalf ("unexpected updated hosts for update: %v, expected: %v, got: %v" , idx , expectedUpdateCalls [idx ].Hosts , update .Hosts )
1460
+ }
1461
+ }
1462
+ if len (expectedEnsureCalls ) != len (cloudProvider .EnsureCalls ) {
1463
+ t .Fatalf ("unexpected amount of ensure calls, expected: %v, got: %v" , len (expectedEnsureCalls ), len (cloudProvider .EnsureCalls ))
1464
+ }
1465
+ for idx , ensure := range cloudProvider .EnsureCalls {
1466
+ if ! compareHostSets (t , expectedEnsureCalls [idx ].Hosts , ensure .Hosts ) {
1467
+ t .Fatalf ("unexpected updated hosts for ensure: %v, expected: %v, got: %v" , idx , expectedEnsureCalls [idx ].Hosts , ensure .Hosts )
1468
+ }
1469
+ }
1487
1470
}
1488
1471
1489
1472
func TestNeedsUpdate (t * testing.T ) {
0 commit comments