Skip to content

Commit 8468bcf

Browse files
Increase retry time during dll restore (#869)
Increase retry time during dll restore
1 parent 4974550 commit 8468bcf

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/coverlet.core/Helpers/InstrumentationHelper.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Coverlet.Core.Helpers
1515
{
1616
internal class InstrumentationHelper : IInstrumentationHelper
1717
{
18+
private const int RetryAttempts = 12;
1819
private readonly ConcurrentDictionary<string, string> _backupList = new ConcurrentDictionary<string, string>();
1920
private readonly IRetryHelper _retryHelper;
2021
private readonly IFileSystem _fileSystem;
@@ -216,7 +217,7 @@ public virtual void RestoreOriginalModule(string module, string identifier)
216217
_fileSystem.Copy(backupPath, module, true);
217218
_fileSystem.Delete(backupPath);
218219
_backupList.TryRemove(module, out string _);
219-
}, retryStrategy, 10);
220+
}, retryStrategy, RetryAttempts);
220221

221222
_retryHelper.Retry(() =>
222223
{
@@ -227,7 +228,7 @@ public virtual void RestoreOriginalModule(string module, string identifier)
227228
_fileSystem.Delete(backupSymbolPath);
228229
_backupList.TryRemove(symbolFile, out string _);
229230
}
230-
}, retryStrategy, 10);
231+
}, retryStrategy, RetryAttempts);
231232
}
232233

233234
public virtual void RestoreOriginalModules()
@@ -244,16 +245,14 @@ public virtual void RestoreOriginalModules()
244245
_fileSystem.Copy(backupPath, key, true);
245246
_fileSystem.Delete(backupPath);
246247
_backupList.TryRemove(key, out string _);
247-
}, retryStrategy, 10);
248+
}, retryStrategy, RetryAttempts);
248249
}
249250
}
250251

251252
public void DeleteHitsFile(string path)
252253
{
253-
// Retry hitting the hits file - retry up to 10 times, since the file could be locked
254-
// See: https://github.com/tonerdo/coverlet/issues/25
255254
var retryStrategy = CreateRetryStrategy();
256-
_retryHelper.Retry(() => _fileSystem.Delete(path), retryStrategy, 10);
255+
_retryHelper.Retry(() => _fileSystem.Delete(path), retryStrategy, RetryAttempts);
257256
}
258257

259258
public bool IsValidFilterExpression(string filter)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ class CustomRetryHelper : IRetryHelper
178178
public T Do<T>(Func<T> action, Func<TimeSpan> backoffStrategy, int maxAttemptCount = 3)
179179
{
180180
var exceptions = new List<Exception>();
181-
182181
for (int attempted = 0; attempted < maxAttemptCount; attempted++)
183182
{
184183
try
@@ -191,7 +190,7 @@ public T Do<T>(Func<T> action, Func<TimeSpan> backoffStrategy, int maxAttemptCou
191190
}
192191
catch (Exception ex)
193192
{
194-
if (ex.ToString().Contains("RestoreOriginalModules"))
193+
if (ex.ToString().Contains("RestoreOriginalModules") || ex.ToString().Contains("RestoreOriginalModule"))
195194
{
196195
// If we're restoring modules mean that process are closing and we cannot override copied test file because is locked so we hide error
197196
// to have a correct process exit value

0 commit comments

Comments
 (0)