File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed
FortnoxSDK/Connectors/Base Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -35,12 +35,15 @@ public async Task Test_RateLimiter_NoError()
3535 watch . Stop ( ) ;
3636
3737 /*
38- * Given the rate limiter of 4 requests per second,
39- * 200 requests should be executed in ~50 seconds.
40- * Note: time per request might be longer than 250ms, hence the longer maximum allowed elapsed time
38+ * Given the rate limiter of 4.8 requests per second (24/5),
39+ * 200 requests should be executed in ~41 seconds.
40+ *
41+ * If we can increase the rate limiter to the advertised 25/5 (5 per second),
42+ * 200 requests should be executed in ~40 seconds.
4143 */
44+
4245 Assert . AreEqual ( 200 , counter ) ;
43- Assert . IsTrue ( watch . Elapsed . TotalSeconds is > 49 and < 65 ) ;
46+ Assert . IsTrue ( watch . Elapsed . TotalSeconds is > 40 ) ;
4447 }
4548
4649 [ Ignore ( "Can make other test fail due to exhausting rate limiter" ) ]
Original file line number Diff line number Diff line change 77namespace Fortnox . SDK . Connectors . Base ;
88
99/// <summary>
10- /// Rate limit - 4 requests per 1 seconds per token
10+ /// Rate limit - 25 requests per 5 seconds per token
1111/// </summary>
1212internal class RateLimiter
1313{
14- private const int MaxCount = 4 ;
15- private static readonly TimeSpan Period = TimeSpan . FromSeconds ( 1 ) ;
14+ private const int MaxCount = 24 ; // Rate limit is 25 requests over 5 second sliding window, but using the max allowed still seems to trigger the limit. 24 req per 5 sec seems to work consistently.
15+ private static readonly TimeSpan Period = TimeSpan . FromSeconds ( 5 ) ;
1616
1717 private static readonly Dictionary < string , TimeLimiter > RateLimiters = new ( ) ;
1818
You can’t perform that action at this time.
0 commit comments