Skip to content

Commit

Permalink
fix more
Browse files Browse the repository at this point in the history
Signed-off-by: hejianpeng <hejianpeng2@huawei.com>
  • Loading branch information
zirain committed Apr 20, 2023
1 parent c3bfaf8 commit 52a2b2b
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions conformance/utils/kubernetes/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ func GatewayAndHTTPRoutesMustBeAccepted(t *testing.T, c client.Client, timeoutCo
func WaitForGatewayAddress(t *testing.T, client client.Client, timeoutConfig config.TimeoutConfig, gwName types.NamespacedName) (string, error) {
t.Helper()

var ipAddr, port string
waitErr := wait.PollImmediate(1*time.Second, timeoutConfig.GatewayMustHaveAddress, func() (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

var ipAddr, port string
waitErr := wait.PollUntilContextTimeout(ctx, 1*time.Second, timeoutConfig.GatewayMustHaveAddress, true, func(_ context.Context) (bool, error) {
gw := &v1beta1.Gateway{}
err := client.Get(ctx, gwName, gw)
if err != nil {
Expand Down Expand Up @@ -325,10 +325,13 @@ func WaitForGatewayAddress(t *testing.T, client client.Client, timeoutConfig con
// may indicate a single listener with zero attached routes or no listeners.
func GatewayMustHaveZeroRoutes(t *testing.T, client client.Client, timeoutConfig config.TimeoutConfig, gwName types.NamespacedName) {
var gotStatus *v1beta1.GatewayStatus
waitErr := wait.PollImmediate(1*time.Second, timeoutConfig.GatewayStatusMustHaveListeners, func() (bool, error) {

ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.GetTimeout)
defer cancel()

waitErr := wait.PollUntilContextTimeout(ctx, 1*time.Second, timeoutConfig.GatewayStatusMustHaveListeners, true, func(_ context.Context) (bool, error) {
gw := &v1beta1.Gateway{}
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.GetTimeout)
defer cancel()

err := client.Get(ctx, gwName, gw)
require.NoError(t, err, "error fetching Gateway")

Expand Down Expand Up @@ -361,11 +364,12 @@ func GatewayMustHaveZeroRoutes(t *testing.T, client client.Client, timeoutConfig
func HTTPRouteMustHaveNoAcceptedParents(t *testing.T, client client.Client, timeoutConfig config.TimeoutConfig, routeName types.NamespacedName) {
t.Helper()

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

var actual []v1beta1.RouteParentStatus
emptyChecked := false
waitErr := wait.PollImmediate(1*time.Second, timeoutConfig.HTTPRouteMustNotHaveParents, func() (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
waitErr := wait.PollUntilContextTimeout(ctx, 1*time.Second, timeoutConfig.HTTPRouteMustNotHaveParents, true, func(_ context.Context) (bool, error) {

route := &v1beta1.HTTPRoute{}
err := client.Get(ctx, routeName, route)
Expand Down Expand Up @@ -409,12 +413,11 @@ func HTTPRouteMustHaveNoAcceptedParents(t *testing.T, client client.Client, time
// if the specified timeout is exceeded.
func HTTPRouteMustHaveParents(t *testing.T, client client.Client, timeoutConfig config.TimeoutConfig, routeName types.NamespacedName, parents []v1beta1.RouteParentStatus, namespaceRequired bool) {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

var actual []v1beta1.RouteParentStatus
waitErr := wait.PollImmediate(1*time.Second, timeoutConfig.RouteMustHaveParents, func() (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

waitErr := wait.PollUntilContextTimeout(ctx, 1*time.Second, timeoutConfig.RouteMustHaveParents, true, func(_ context.Context) (bool, error) {
route := &v1beta1.HTTPRoute{}
err := client.Get(ctx, routeName, route)
if err != nil {
Expand Down Expand Up @@ -443,10 +446,10 @@ func TLSRouteMustHaveParents(t *testing.T, client client.Client, timeoutConfig c
var actual []v1beta1.RouteParentStatus
var route v1alpha2.TLSRoute

waitErr := wait.PollImmediate(1*time.Second, timeoutConfig.RouteMustHaveParents, func() (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

waitErr := wait.PollUntilContextTimeout(ctx, 1*time.Second, timeoutConfig.RouteMustHaveParents, true, func(_ context.Context) (bool, error) {
err := client.Get(ctx, routeName, &route)
if err != nil {
return false, fmt.Errorf("error fetching TLSRoute: %w", err)
Expand Down Expand Up @@ -510,11 +513,11 @@ func parentsForRouteMatch(t *testing.T, routeName types.NamespacedName, expected
func GatewayStatusMustHaveListeners(t *testing.T, client client.Client, timeoutConfig config.TimeoutConfig, gwNN types.NamespacedName, listeners []v1beta1.ListenerStatus) {
t.Helper()

var actual []v1beta1.ListenerStatus
waitErr := wait.PollImmediate(1*time.Second, timeoutConfig.GatewayStatusMustHaveListeners, func() (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

var actual []v1beta1.ListenerStatus
waitErr := wait.PollUntilContextTimeout(ctx, 1*time.Second, timeoutConfig.GatewayStatusMustHaveListeners, true, func(_ context.Context) (bool, error) {
gw := &v1beta1.Gateway{}
err := client.Get(ctx, gwNN, gw)
if err != nil {
Expand All @@ -537,10 +540,10 @@ func GatewayStatusMustHaveListeners(t *testing.T, client client.Client, timeoutC
func HTTPRouteMustHaveCondition(t *testing.T, client client.Client, timeoutConfig config.TimeoutConfig, routeNN types.NamespacedName, gwNN types.NamespacedName, condition metav1.Condition) {
t.Helper()

waitErr := wait.PollImmediate(1*time.Second, timeoutConfig.HTTPRouteMustHaveCondition, func() (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

waitErr := wait.PollUntilContextTimeout(ctx, 1*time.Second, timeoutConfig.HTTPRouteMustHaveCondition, true, func(_ context.Context) (bool, error) {
route := &v1beta1.HTTPRoute{}
err := client.Get(ctx, routeNN, route)
if err != nil {
Expand Down

0 comments on commit 52a2b2b

Please sign in to comment.