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 has been 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.
The text was updated successfully, but these errors were encountered:
An interesting follow-on to this issue could be implementing rollback functionality. Another issue that happens in integration tests from time-to-time is a test failing in an unexpected place and leaving artifacts in the environment which affect the next tests (typically artifacts at the Admin level). A rollback feature could register the commands executed and execute their corollary (for create, delete for example) in the case of failure, such as a finally block.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
A similar example could be done for a CreateCommand, except it will use Func instead of Action as the executing code.
The text was updated successfully, but these errors were encountered: