-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase rate limiter to 4 per second
- Loading branch information
1 parent
60efe53
commit c7a0333
Showing
5 changed files
with
68 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using FortnoxAPILibrary.Connectors; | ||
using FortnoxAPILibrary.Entities; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace FortnoxAPILibrary.Tests | ||
{ | ||
[TestClass] | ||
public class RateLimiterTests | ||
{ | ||
[TestInitialize] | ||
public void Init() | ||
{ | ||
//Set global credentials for SDK | ||
//--- Open 'TestCredentials.resx' to edit the values ---\\ | ||
ConnectionCredentials.AccessToken = TestCredentials.Access_Token; | ||
ConnectionCredentials.ClientSecret = TestCredentials.Client_Secret; | ||
} | ||
|
||
[TestMethod] | ||
public void Test_RateLimiter_NoError() | ||
{ | ||
var connector = new CustomerConnector(); | ||
|
||
var watch = new Stopwatch(); | ||
watch.Start(); | ||
for (var i = 0; i < 200; i++) | ||
{ | ||
connector.City = TestUtils.RandomString(); //Needs to be random to make unique GET request | ||
connector.Find(); | ||
MyAssert.HasNoError(connector); | ||
} | ||
|
||
watch.Stop(); | ||
Console.WriteLine(@"Total time: " + watch.ElapsedMilliseconds); | ||
} | ||
|
||
[TestMethod] | ||
public void Test_NoRateLimiter_TooManyRequest_Error() | ||
{ | ||
ConnectionSettings.UseRateLimiter = false; | ||
var connector = new CustomerConnector(); | ||
|
||
ErrorInformation error = null; | ||
for (var i = 0; i < 200; i++) | ||
{ | ||
connector.City = TestUtils.RandomString(); | ||
connector.Find(); | ||
if (connector.HasError) | ||
{ | ||
error = connector.Error; | ||
break; | ||
} | ||
} | ||
|
||
//Restore settings | ||
ConnectionSettings.UseRateLimiter = true; | ||
|
||
//Assert | ||
//Assert.IsTrue(failed > 0); | ||
Assert.IsNotNull(error); | ||
Assert.IsTrue(error.Message.Contains("Too Many Requests")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters