Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: expect resposne code for positive cases #3990

Open
wants to merge 5 commits into
base: v3.x.x
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class InMemoryRateLimiterFilterFactoryIntegrationTest {

private static WebTestClient client;

final int bucketCapacity = 60;
final int bucketCapacity = 20;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this number was specified for HA integration tests, could you verify this branch with the ITs pipeline?
If it needs to be updated we should have it parameterized depending on whether it's run as HA or single instance

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, in our HA ITs it was failing, because the calls are routed randomly to different GW instances and the rate limit is set on instance level so it might never reach this limit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now configurable via "gateway.bucketCapacity." I'm not sure if that would solve your problem with HA, as it can still be random, and you will not get the exact number of requests for each instance. It was probably passing due to missing the lower boundary check.


@BeforeAll
static void setUpTester() {
Expand Down Expand Up @@ -67,22 +67,23 @@ void testRateLimitingWhenAllowedWithCookie() {
void testRateLimitingWhenExceeded() {
IntStream.range(0, bucketCapacity).parallel().forEach(i -> client.get()
.cookie("apimlAuthenticationToken", "validTokenValue")
.exchange());
.exchange().expectStatus().isOk());


client.get()
.cookie("apimlAuthenticationToken", "validTokenValue")
.exchange()
.expectStatus().isEqualTo(HttpStatus.TOO_MANY_REQUESTS)
.expectBody()
.jsonPath("$.messages[0].messageReason").isEqualTo("Connections limit exceeded.");;
.jsonPath("$.messages[0].messageReason").isEqualTo("Connections limit exceeded.");
}

@Test
void testRateLimiterAllowsAccessToAnotherUser() {
// the first user requires access
IntStream.range(0, bucketCapacity).parallel().forEach(i -> client.get()
.cookie("apimlAuthenticationToken", "theFirstUser")
.exchange());
.exchange().expectStatus().isOk());
//access should be denied
client.get()
.cookie("apimlAuthenticationToken", "theFirstUser")
Expand Down
Loading