Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/coverlet.core/Coverage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,18 @@ public CoverageResult GetCoverageResult()

if (!string.IsNullOrEmpty(_mergeWith) && !string.IsNullOrWhiteSpace(_mergeWith) && File.Exists(_mergeWith))
{
string json = File.ReadAllText(_mergeWith);
// Possible concurrency access to merge file between write/read on parallel testing
var json = RetryHelper.Do(() =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you add some comment above like // Possible concurrency access to merge file between write/read on parallel testing here and below?

{
using (var file = File.Open(_mergeWith, FileMode.Open, FileAccess.Read, FileShare.None))
{
using (var reader = new StreamReader(file))
{
return reader.ReadToEnd();
}
}
}, () => TimeSpan.FromMilliseconds(100), 5);
Copy link
Collaborator

@MarcoRossignoli MarcoRossignoli Feb 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about max attempt, I would try for "more standard seconds" 10 or 30 /cc @petli @tonerdo


coverageResult.Merge(JsonConvert.DeserializeObject<Modules>(json));
}

Expand Down
15 changes: 14 additions & 1 deletion src/coverlet.msbuild.tasks/CoverageResultTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,20 @@ public override bool Execute()

var report = Path.Combine(directory, filename);
Console.WriteLine($" Generating report '{report}'");
File.WriteAllText(report, reporter.Report(result));

var resultContent = reporter.Report(result);

// Possible concurrency access to merge file between write/read on parallel testing
RetryHelper.Retry(() =>
{
using (var file = File.Open(report, FileMode.Create, FileAccess.Write, FileShare.None))
{
using (var writer = new StreamWriter(file))
{
writer.Write(resultContent);
}
}
}, () => TimeSpan.FromMilliseconds(100), 5);
}
}

Expand Down