DaanHoogland commented on code in PR #6984:
URL: https://github.com/apache/cloudstack/pull/6984#discussion_r1048224921
##########
plugins/api/rate-limit/src/test/java/org/apache/cloudstack/ratelimit/ApiRateLimitTest.java:
##########
@@ -110,17 +110,26 @@ public void sequentialApiAccess() {
@Test
public void canDoReasonableNumberOfApiAccessPerSecond() throws Exception {
- int allowedRequests = 200;
+ int allowedRequests = 2000;
Review Comment:
```suggestion
int allowedRequests = 200;
```
##########
plugins/api/rate-limit/src/test/java/org/apache/cloudstack/ratelimit/ApiRateLimitTest.java:
##########
@@ -110,17 +110,26 @@ public void sequentialApiAccess() {
@Test
public void canDoReasonableNumberOfApiAccessPerSecond() throws Exception {
- int allowedRequests = 200;
+ int allowedRequests = 2000;
s_limitService.setMaxAllowed(allowedRequests);
- s_limitService.setTimeToLive(1);
+ s_limitService.setTimeToLive(5);
+ long startTime = System.nanoTime();
User key = createFakeUser();
for (int i = 0; i < allowedRequests; i++) {
- assertTrue("We should allow " + allowedRequests + " requests per
second, but failed at request " + i, isUnderLimit(key));
+ assertTrue(String.format("We should allow %d requests per second,
but failed at request %d.", allowedRequests, i), isUnderLimit(key));
}
-
- assertFalse("We should block >" + allowedRequests + " requests per
second", isUnderLimit(key));
+ // we cannot really say more about this test
+ boolean underLimit = isUnderLimit(key);
+ long endtime = System.nanoTime();
+ int issued = s_limitService.getIssued(key.getAccountId());
+ int timeToLive = s_limitService.getTimeToLive();
+
+ // this assertion is really invalid as we don´t know if we exceeded
the time to live for the amount of api calls (for sure)
+ // so only fail if timeToLive is not exeeded and we didn´t get the
requested number of calls
+ assertTrue(String.format("We should block >%d requests per %d seconds
(managed %d, time elapsed %d)",
+ s_limitService.getMaxAllowed(), timeToLive, issued, endtime -
startTime), ( ! underLimit) || ((endtime - starttime)/1000000 > timeToLive);
Review Comment:
```suggestion
// this assertion is really invalid as we don´t know if we exceeded
the time to live for the amount of api calls (for sure)
// so only fail if timeToLive is not exeeded and we didn´t get the
requested number of calls
assertFalse(String.format("We should block >%d requests per %d
seconds (managed %d, time elapsed %d)",
s_limitService.getMaxAllowed(), timeToLive, issued, endtime
- startTime), ((endtime - starttime)/1000000 < timeToLive) && underLimit);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]