Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Implement Retry Across Helpers #35

@abilson

Description

@abilson

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions