DaanHoogland commented on code in PR #6984:
URL: https://github.com/apache/cloudstack/pull/6984#discussion_r1048187925


##########
plugins/api/rate-limit/src/test/java/org/apache/cloudstack/ratelimit/ApiRateLimitTest.java:
##########
@@ -110,17 +110,25 @@ 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)
+        assertFalse(String.format("We should block >%d requests per %d seconds 
(managed %d, time elapsed %d)",
+                s_limitService.getMaxAllowed(), timeToLive, issued, endtime - 
startTime), underLimit);

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
           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);
   ```



##########
plugins/api/rate-limit/src/test/java/org/apache/cloudstack/ratelimit/ApiRateLimitTest.java:
##########
@@ -110,17 +110,25 @@ 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)
+        assertFalse(String.format("We should block >%d requests per %d seconds 
(managed %d, time elapsed %d)",
+                s_limitService.getMaxAllowed(), timeToLive, issued, endtime - 
startTime), underLimit);

Review Comment:
   @davidjumani @nvazquez @weizhouapache , I did a self review and I think we 
need this extra condition



-- 
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: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to