Skip to content

Commit

Permalink
Fix flaky tests
Browse files Browse the repository at this point in the history
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
  • Loading branch information
shadi-altarsha committed Jun 10, 2023
1 parent 5254299 commit 0b03e57
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 81 deletions.
84 changes: 14 additions & 70 deletions test/e2e/httpproxy/default_global_rate_limiting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func testDefaultGlobalRateLimitingVirtualHostNonTLS(namespace string) {
p := &contourv1.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "globalratelimitvhostnontls",
Name: "defaultglobalratelimitvhostnontls",
},
Spec: contourv1.HTTPProxySpec{
VirtualHost: &contourv1.VirtualHost{
Fqdn: "globalratelimitvhostnontls.projectcontour.io",
Fqdn: "defaultglobalratelimitvhostnontls.projectcontour.io",
},
Routes: []contourv1.Route{
{
Expand All @@ -54,23 +54,9 @@ func testDefaultGlobalRateLimitingVirtualHostNonTLS(namespace string) {
}
p, _ = f.CreateHTTPProxyAndWaitFor(p, e2e.HTTPProxyValid)

// Wait until we get a 200 from the proxy confirming
// the pods are up and serving traffic.
res, ok := f.HTTP.RequestUntil(&e2e.HTTPRequestOpts{
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
RequestOpts: []func(*http.Request){
e2e.OptSetHeaders(map[string]string{
"X-Default-Header": "test_value_1",
}),
},
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Make another request against the proxy, confirm a 429 response
// is now gotten since we've exceeded the rate limit.
res, ok = f.HTTP.RequestUntil(&e2e.HTTPRequestOpts{
res, ok := f.HTTP.RequestUntil(&e2e.HTTPRequestOpts{
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(429),
RequestOpts: []func(*http.Request){
Expand All @@ -91,11 +77,11 @@ func testDefaultGlobalRateLimitingVirtualHostNonTLS(namespace string) {
p := &contourv1.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "globalratelimitvhostnontls",
Name: "defaultglobalratelimitvhostnontls",
},
Spec: contourv1.HTTPProxySpec{
VirtualHost: &contourv1.VirtualHost{
Fqdn: "globalratelimitvhostnontls.projectcontour.io",
Fqdn: "defaultglobalratelimitvhostnontls.projectcontour.io",
RateLimitPolicy: &contourv1.RateLimitPolicy{
Global: &contourv1.GlobalRateLimitPolicy{
DefaultGlobalRateLimitPolicyDisabled: true,
Expand Down Expand Up @@ -153,11 +139,11 @@ func testDefaultGlobalRateLimitingVirtualHostNonTLS(namespace string) {
p := &contourv1.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "globalratelimitvhostnontls",
Name: "defaultglobalratelimitvhostnontls",
},
Spec: contourv1.HTTPProxySpec{
VirtualHost: &contourv1.VirtualHost{
Fqdn: "globalratelimitvhostnontls.projectcontour.io",
Fqdn: "defaultglobalratelimitvhostnontls.projectcontour.io",
RateLimitPolicy: &contourv1.RateLimitPolicy{
Global: &contourv1.GlobalRateLimitPolicy{
Descriptors: []contourv1.RateLimitDescriptor{
Expand Down Expand Up @@ -202,20 +188,6 @@ func testDefaultGlobalRateLimitingVirtualHostNonTLS(namespace string) {
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Make another request against the proxy, confirm a 429 response
// is now gotten since we've exceeded the rate limit.
res, ok = f.HTTP.RequestUntil(&e2e.HTTPRequestOpts{
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
RequestOpts: []func(*http.Request){
e2e.OptSetHeaders(map[string]string{
"X-Default-Header": "test_value_3",
}),
},
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Make another request against the proxy, confirm a 429 response
// is now gotten since we've exceeded the rate limit.
res, ok = f.HTTP.RequestUntil(&e2e.HTTPRequestOpts{
Expand All @@ -242,11 +214,11 @@ func testDefaultGlobalRateLimitingVirtualHostTLS(namespace string) {
p := &contourv1.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "globalratelimitvhostnontls",
Name: "defaultglobalratelimitvhostnontls",
},
Spec: contourv1.HTTPProxySpec{
VirtualHost: &contourv1.VirtualHost{
Fqdn: "globalratelimitvhostnontls.projectcontour.io",
Fqdn: "defaultglobalratelimitvhostnontls.projectcontour.io",
TLS: &contourv1.TLS{
SecretName: "echo",
},
Expand All @@ -265,23 +237,9 @@ func testDefaultGlobalRateLimitingVirtualHostTLS(namespace string) {
}
p, _ = f.CreateHTTPProxyAndWaitFor(p, e2e.HTTPProxyValid)

// Wait until we get a 200 from the proxy confirming
// the pods are up and serving traffic.
res, ok := f.HTTP.SecureRequestUntil(&e2e.HTTPSRequestOpts{
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
RequestOpts: []func(*http.Request){
e2e.OptSetHeaders(map[string]string{
"X-Default-Header": "test_value_4",
}),
},
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Make another request against the proxy, confirm a 429 response
// is now gotten since we've exceeded the rate limit.
res, ok = f.HTTP.SecureRequestUntil(&e2e.HTTPSRequestOpts{
res, ok := f.HTTP.SecureRequestUntil(&e2e.HTTPSRequestOpts{
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(429),
RequestOpts: []func(*http.Request){
Expand All @@ -303,11 +261,11 @@ func testDefaultGlobalRateLimitingVirtualHostTLS(namespace string) {
p := &contourv1.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "globalratelimitvhostnontls",
Name: "defaultglobalratelimitvhostnontls",
},
Spec: contourv1.HTTPProxySpec{
VirtualHost: &contourv1.VirtualHost{
Fqdn: "globalratelimitvhostnontls.projectcontour.io",
Fqdn: "defaultglobalratelimitvhostnontls.projectcontour.io",
TLS: &contourv1.TLS{
SecretName: "echo",
},
Expand Down Expand Up @@ -369,11 +327,11 @@ func testDefaultGlobalRateLimitingVirtualHostTLS(namespace string) {
p := &contourv1.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "globalratelimitvhostnontls",
Name: "defaultglobalratelimitvhostnontls",
},
Spec: contourv1.HTTPProxySpec{
VirtualHost: &contourv1.VirtualHost{
Fqdn: "globalratelimitvhostnontls.projectcontour.io",
Fqdn: "defaultglobalratelimitvhostnontls.projectcontour.io",
TLS: &contourv1.TLS{
SecretName: "echo",
},
Expand Down Expand Up @@ -421,20 +379,6 @@ func testDefaultGlobalRateLimitingVirtualHostTLS(namespace string) {
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Make another request against the proxy, confirm a 429 response
// is now gotten since we've exceeded the rate limit.
res, ok = f.HTTP.SecureRequestUntil(&e2e.HTTPSRequestOpts{
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
RequestOpts: []func(*http.Request){
e2e.OptSetHeaders(map[string]string{
"X-Default-Header": "test_value_6",
}),
},
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Make another request against the proxy, confirm a 429 response
// is now gotten since we've exceeded the rate limit.
res, ok = f.HTTP.SecureRequestUntil(&e2e.HTTPSRequestOpts{
Expand Down
36 changes: 25 additions & 11 deletions test/e2e/httpproxy/httpproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,22 +455,36 @@ descriptors:
Domain: "contour-default-global-rate-limit",
FailOpen: ref.To(false),
EnableXRateLimitHeaders: ref.To(false),
DefaultGlobalRateLimitPolicy: &contour_api_v1.GlobalRateLimitPolicy{
Descriptors: []contour_api_v1.RateLimitDescriptor{
{
Entries: []contour_api_v1.RateLimitDescriptorEntry{
{
RequestHeader: &contour_api_v1.RequestHeaderDescriptor{
HeaderName: "X-Default-Header",
DescriptorKey: "defaultHeader",
},
},
},
},
},
},
}
require.NoError(f.T(),
f.Deployment.EnsureRateLimitResources(
namespace,
`
domain: contour-default-global-rate-limit
descriptors:
- key: generic_key
value: foo
rate_limit:
unit: hour
requests_per_unit: 2
- key: defaultHeader
rate_limit:
unit: hour
requests_per_unit: 1`))
domain: contour-default-global-rate-limit
descriptors:
- key: generic_key
value: foo
rate_limit:
unit: hour
requests_per_unit: 1
- key: defaultHeader
rate_limit:
unit: hour
requests_per_unit: 1`))
})

body(namespace)
Expand Down

0 comments on commit 0b03e57

Please sign in to comment.