0

I have inherited SqlServerRetryingExecutionStrategy from Code sample by Microsoft in GitHub, called MySQLServerRetryPolicy class

I have added a cancellationtoken in ShouldRetryOn overriden method in MySQLServerRetryPolicy, so I could kill the NET.Core console by pressing Ctrl+C. Here is the code snippet below:

protected override bool ShouldRetryOn(Exception exception) {
        _retryCancellationToken.ThrowIfCancellationRequested();}

Here is how I use MySQLServerRetryPolicy:

                builder.UseSqlServer(ConnectionString, options => {
                options.ExecutionStrategy(exeStrategyDependencies=>
                                              new MySQLServerRetryPolicy(
                                                  exeStrategyDependencies, _errorNumRetryList, RetryCancelToken.Token));

builder variable above is type of DbContextOptionsBuilder.

However, in the unit test, there is no output telling if the SQl retry policy running forever.

Question: How do I ignore or skip the SQL retry policy in the unit tests?

Unknown
  • 778
  • 1
  • 7
  • 16
  • i wouldn't inherit from the `SqlServerPolicy` it really pollutes your mysql stuff. – Daniel A. White Mar 08 '19 at 13:09
  • @DanielA.White, sorry I do not get your comment. Do you mean that you would avoid inherit from `SqlServerRetryingExecutionStrategy` ? – Unknown Mar 08 '19 at 13:12
  • 1
    ShouldRetryOn returns a bool. If you don't want to retry, return false. It's not clear from this question, but assuming you want to use your production bootstrapping code in your test, you can add a condition based on the environment before adding the retry policy. But if you're having troubles with the retries it's probably not a unit test. – fsimonazzi Mar 08 '19 at 13:12
  • yes inherit from ExecutionPolicy – Daniel A. White Mar 08 '19 at 13:13
  • what are you unit testing? perhaps you should use the in memory provider. – Daniel A. White Mar 08 '19 at 13:22
  • @DanielA.White, I have in memory provider & SQL in unit test. I am required to use SQL as part of my unit tests. – Unknown Mar 08 '19 at 13:30

0 Answers0