Skip to content

Commit b53d0aa

Browse files
committed
revert update for RetryHelper handledExceptions parameter
1 parent 312cb59 commit b53d0aa

File tree

6 files changed

+20
-88
lines changed

6 files changed

+20
-88
lines changed

src/coverlet.core/Abstractions/IRetryHelper.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5-
using System.Collections.Generic;
65

76
namespace Coverlet.Core.Abstractions
87
{
98
internal interface IRetryHelper
109
{
11-
void Retry(Action action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3, List<Type> handledExceptions = null);
12-
T Do<T>(Func<T> action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3, List<Type> handledExceptions = null);
10+
void Retry(Action action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3);
11+
T Do<T>(Func<T> action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3);
1312
}
1413
}

src/coverlet.core/Helpers/InstrumentationHelper.cs

+5-8
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public virtual void RestoreOriginalModule(string module, string identifier)
290290
_fileSystem.Copy(backupPath, module, true);
291291
_fileSystem.Delete(backupPath);
292292
_backupList.TryRemove(module, out string _);
293-
}, retryStrategy, RetryAttempts, _retryExceptionList);
293+
}, retryStrategy, RetryAttempts);
294294

295295
_retryHelper.Retry(() =>
296296
{
@@ -301,7 +301,7 @@ public virtual void RestoreOriginalModule(string module, string identifier)
301301
_fileSystem.Delete(backupSymbolPath);
302302
_backupList.TryRemove(symbolFile, out string _);
303303
}
304-
}, retryStrategy, RetryAttempts, _retryExceptionList);
304+
}, retryStrategy, RetryAttempts);
305305
}
306306

307307
public virtual void RestoreOriginalModules()
@@ -318,14 +318,14 @@ public virtual void RestoreOriginalModules()
318318
_fileSystem.Copy(backupPath, key, true);
319319
_fileSystem.Delete(backupPath);
320320
_backupList.TryRemove(key, out string _);
321-
}, retryStrategy, RetryAttempts, _retryExceptionList);
321+
}, retryStrategy, RetryAttempts);
322322
}
323323
}
324324

325325
public void DeleteHitsFile(string path)
326326
{
327327
Func<TimeSpan> retryStrategy = CreateRetryStrategy();
328-
_retryHelper.Retry(() => _fileSystem.Delete(path), retryStrategy, RetryAttempts, _retryExceptionList);
328+
_retryHelper.Retry(() => _fileSystem.Delete(path), retryStrategy, RetryAttempts);
329329
}
330330

331331
public bool IsValidFilterExpression(string filter)
@@ -393,10 +393,7 @@ private string GetModuleKeysForExcludeFilters(IEnumerable<string> filters, char
393393

394394
private string[] GetValidFilters(IEnumerable<string> filters)
395395
{
396-
return (filters ?? Array.Empty<string>())
397-
.Where(IsValidFilterExpression)
398-
.Where(x => x.EndsWith("*"))
399-
.ToArray();
396+
return [.. (filters ?? []).Where(IsValidFilterExpression).Where(x => x.EndsWith("*"))];
400397
}
401398

402399
private static string GetExcludeModuleKeysForValidFilters(char escapeSymbol, string moduleKeys, string[] validFilters)

src/coverlet.core/Helpers/RetryHelper.cs

+6-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.IO;
67
using System.Threading;
78
using Coverlet.Core.Abstractions;
89

@@ -18,18 +19,16 @@ internal class RetryHelper : IRetryHelper
1819
/// <param name="action">The action to perform</param>
1920
/// <param name="backoffStrategy">A function returning a Timespan defining the backoff strategy to use.</param>
2021
/// <param name="maxAttemptCount">The maximum number of retries before bailing out. Defaults to 3.</param>
21-
/// <param name="handledExceptions">A list of exception types to handle. Defaults to handling all exceptions.</param>
2222
public void Retry(
2323
Action action,
2424
Func<TimeSpan> backoffStrategy,
25-
int maxAttemptCount = 3,
26-
List<Type> handledExceptions = null)
25+
int maxAttemptCount = 3)
2726
{
2827
Do<object>(() =>
2928
{
3029
action();
3130
return null;
32-
}, backoffStrategy, maxAttemptCount, handledExceptions);
31+
}, backoffStrategy, maxAttemptCount);
3332
}
3433

3534
/// <summary>
@@ -39,12 +38,10 @@ public void Retry(
3938
/// <param name="action">The action to perform</param>
4039
/// <param name="backoffStrategy">A function returning a Timespan defining the backoff strategy to use.</param>
4140
/// <param name="maxAttemptCount">The maximum number of retries before bailing out. Defaults to 3.</param>
42-
/// <param name="handledExceptions">A list of exception types to handle. Defaults to handling all exceptions.</param>
4341
public T Do<T>(
4442
Func<T> action,
4543
Func<TimeSpan> backoffStrategy,
46-
int maxAttemptCount = 3,
47-
List<Type> handledExceptions = null)
44+
int maxAttemptCount = 3)
4845
{
4946
var exceptions = new List<Exception>();
5047

@@ -58,16 +55,9 @@ public T Do<T>(
5855
}
5956
return action();
6057
}
61-
catch (Exception ex)
58+
catch (IOException ex)
6259
{
63-
if (handledExceptions == null || handledExceptions.Contains(ex.GetType()))
64-
{
65-
exceptions.Add(ex);
66-
}
67-
else
68-
{
69-
throw;
70-
}
60+
exceptions.Add(ex);
7161
}
7262
}
7363
throw new AggregateException(exceptions);

test/coverlet.core.coverage.tests/Coverage/InstrumenterHelper.cs

+4-11
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public void Add(EventHandler handler)
213213

214214
class CustomRetryHelper : IRetryHelper
215215
{
216-
public T Do<T>(Func<T> action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3, List<Type> handledExceptions = null)
216+
public T Do<T>(Func<T> action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3)
217217
{
218218
var exceptions = new List<Exception>();
219219
for (int attempted = 0; attempted < maxAttemptCount; attempted++)
@@ -226,7 +226,7 @@ public T Do<T>(Func<T> action, Func<TimeSpan> backoffStrategy, int maxAttemptCou
226226
}
227227
return action();
228228
}
229-
catch (Exception ex)
229+
catch (IOException ex)
230230
{
231231
if (ex.ToString().Contains("RestoreOriginalModules") || ex.ToString().Contains("RestoreOriginalModule"))
232232
{
@@ -236,21 +236,14 @@ public T Do<T>(Func<T> action, Func<TimeSpan> backoffStrategy, int maxAttemptCou
236236
}
237237
else
238238
{
239-
if (handledExceptions == null || handledExceptions.Contains(ex.GetType()))
240-
{
241-
exceptions.Add(ex);
242-
}
243-
else
244-
{
245-
throw new AggregateException(exceptions);
246-
}
239+
exceptions.Add(ex);
247240
}
248241
}
249242
}
250243
throw new AggregateException(exceptions);
251244
}
252245

253-
public void Retry(Action action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3, List<Type> handledExceptions = null)
246+
public void Retry(Action action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3)
254247
{
255248
Do<object>(() =>
256249
{

test/coverlet.core.tests/Coverage/InstrumenterHelper.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public void Add(EventHandler handler)
202202

203203
class CustomRetryHelper : IRetryHelper
204204
{
205-
public T Do<T>(Func<T> action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3, List<Type> handledExceptions = null)
205+
public T Do<T>(Func<T> action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3)
206206
{
207207
var exceptions = new List<Exception>();
208208
for (int attempted = 0; attempted < maxAttemptCount; attempted++)
@@ -225,21 +225,14 @@ public T Do<T>(Func<T> action, Func<TimeSpan> backoffStrategy, int maxAttemptCou
225225
}
226226
else
227227
{
228-
if (handledExceptions == null || handledExceptions.Contains(ex.GetType()))
229-
{
230-
exceptions.Add(ex);
231-
}
232-
else
233-
{
234-
throw new AggregateException(exceptions);
235-
}
228+
exceptions.Add(ex);
236229
}
237230
}
238231
}
239232
throw new AggregateException(exceptions);
240233
}
241234

242-
public void Retry(Action action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3, List<Type> handledExceptions = null)
235+
public void Retry(Action action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3)
243236
{
244237
Do<object>(() =>
245238
{

test/coverlet.core.tests/Helpers/RetryHelperTests.cs

-40
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.IO;
76
using Coverlet.Core.Helpers;
87
using Xunit;
@@ -65,45 +64,6 @@ public void TestRetryFinishesIfSuccessful()
6564
new RetryHelper().Retry(() => target.TargetActionThrows5Times(), retryStrategy, 20);
6665
Assert.Equal(6, target.Calls);
6766
}
68-
69-
[Fact]
70-
public void TestRetryHandlesNotIOException()
71-
{
72-
Func<TimeSpan> retryStrategy = () =>
73-
{
74-
return TimeSpan.FromMilliseconds(1);
75-
};
76-
77-
var target = new RetryTarget();
78-
try
79-
{
80-
new RetryHelper().Retry(() => target.TargetActionThrows(), retryStrategy, 7, new List<Type> { typeof(IOException) });
81-
}
82-
catch
83-
{
84-
Assert.Equal(1, target.Calls);
85-
}
86-
}
87-
88-
[Fact]
89-
public void TestRetryHandlesForIOException()
90-
{
91-
Func<TimeSpan> retryStrategy = () =>
92-
{
93-
return TimeSpan.FromMilliseconds(1);
94-
};
95-
96-
var target = new RetryTargetIOException();
97-
try
98-
{
99-
new RetryHelper().Retry(() => target.TargetActionThrows(), retryStrategy, 7, new List<Type> { typeof(IOException) });
100-
}
101-
catch
102-
{
103-
Assert.Equal(7, target.Calls);
104-
}
105-
}
106-
10767
}
10868

10969
public class RetryTarget

0 commit comments

Comments
 (0)