You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2022/12/14 09:06:37 UTC

[GitHub] [cloudstack] DaanHoogland commented on a diff in pull request #6984: make api rate limit test a little more robust

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



-- 
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-unsubscribe@cloudstack.apache.org

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