You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 28, 2022. It is now read-only.
One issue faced by many who run integration tests is the fickle nature of RSAPI calls in a test environment. At times this leads to failed tests because a setup method didn't succeed. A typical way to handle this is to implement retry functionality. Here's a proposed implementation:
The Command pattern is a common solution to the problem of retry. We could implement an abstract class like the one below and inherit from it commands for each helper method as we need it.
public abstract HelperCommand
{
int NumberOfRetries = Constant.NumberOfRetries;
int CurrentRetryCount = 0;
public void IncrementRetry() => CurrentRetryCount++;
public bool TryAgain() => CurrentRetryCount >= NumberOfRetries;
}
public DeleteCommand : HelperCommand
{
private Action _actionToExecute;
public DeleteCommand(Action actionToExecute)
{
_actionToExecute = actionToExecute;
}
public void Execute()
{
do
{
try { _actionToExecute.Invoke(); }
catch (Exception e)
{
base.IncrementRetry();
// handle exception
}
} while (base.TryAgain())
}
}
// Usage example
public void Delete()
{
var deleteCommand = new DeleteCommand( () => DeleteUser(userID) );
deleteCommand.Execute();
}
A similar example could be done for a CreateCommand, except it will use Func instead of Action as the executing code.