@@ -1599,7 +1599,18 @@ func waitForRouterToBecomeAvailable(host string, port int) error {
1599
1599
1600
1600
// waitForRouterToBecomeReady checks that the router is ready.
1601
1601
func waitForRouterToBecomeReady (host string , port int ) error {
1602
- return waitForRouter (host , port , "ready" )
1602
+ // Need to poll because before the router becomes ready the
1603
+ // readiness uri will return 401 instead of 503.
1604
+ return wait .Poll (time .Millisecond * 100 , 30 * time .Second , func () (bool , error ) {
1605
+ err := waitForRouter (host , port , "ready" )
1606
+ if err == nil {
1607
+ return true , nil
1608
+ } else if err == ErrUnauthenticated {
1609
+ return false , nil
1610
+ } else {
1611
+ return false , err
1612
+ }
1613
+ })
1603
1614
}
1604
1615
1605
1616
func makeRouterRequest (t * testing.T , scheme string ) (* http.Response , error ) {
@@ -1648,7 +1659,7 @@ func TestRouterBindsPortsAfterSync(t *testing.T) {
1648
1659
t .Fatalf ("Unexpected error while waiting for the router to become available: %v" , err )
1649
1660
}
1650
1661
1651
- err = waitForRouterToBecomeReady (routerIP , statsPort )
1662
+ err = waitForRouter (routerIP , statsPort , "ready" )
1652
1663
if err == nil {
1653
1664
t .Fatalf ("Router is unexpectedly ready" )
1654
1665
} else if err != ErrUnauthenticated {
@@ -1674,41 +1685,8 @@ func TestRouterBindsPortsAfterSync(t *testing.T) {
1674
1685
t .Fatalf ("Unable to start http server: %v" , err )
1675
1686
}
1676
1687
1677
- // Create events that will allow the router to have enough state to consider itself 'ready'
1678
- httpEndpoint , err := getEndpoint (fakeMasterAndPod .PodHttpAddr )
1679
- if err != nil {
1680
- t .Fatalf ("Couldn't get http endpoint: %v" , err )
1681
- }
1682
- endpointEvent := & watch.Event {
1683
- Type : watch .Added ,
1684
- Object : & kapi.Endpoints {
1685
- ObjectMeta : kapi.ObjectMeta {
1686
- Name : "myService" ,
1687
- Namespace : "default" ,
1688
- },
1689
- Subsets : []kapi.EndpointSubset {httpEndpoint },
1690
- },
1691
- }
1692
- routeEvent := & watch.Event {
1693
- Type : watch .Added ,
1694
- Object : & routeapi.Route {
1695
- ObjectMeta : kapi.ObjectMeta {
1696
- Name : "path" ,
1697
- Namespace : "default" ,
1698
- },
1699
- Spec : routeapi.RouteSpec {
1700
- Host : "www.example.com" ,
1701
- Path : "/test" ,
1702
- To : routeapi.RouteTargetReference {
1703
- Name : "myService" ,
1704
- },
1705
- TLS : & routeapi.TLSConfig {},
1706
- },
1707
- },
1708
- }
1709
- sendTimeout (t , fakeMasterAndPod .EndpointChannel , eventString (endpointEvent ), 30 * time .Second )
1710
- sendTimeout (t , fakeMasterAndPod .RouteChannel , eventString (routeEvent ), 30 * time .Second )
1711
-
1688
+ // The router should now be able to sync with the api and become
1689
+ // ready even without any routes or endopints.
1712
1690
if err = waitForRouterToBecomeReady (routerIP , statsPort ); err != nil {
1713
1691
t .Fatalf ("Unexpected error while waiting for router to become ready: %v" , err )
1714
1692
}
0 commit comments