Skip to content

Commit

Permalink
Merge pull request coverlet-coverage#102 from MaartenX/nunit3-domainu…
Browse files Browse the repository at this point in the history
…nload

Added DomainUnloaded event.
  • Loading branch information
tonerdo committed May 18, 2018
2 parents e3cf833 + f0b7463 commit 2d21f93
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/coverlet.core/CoverageTracker.cs
Expand Up @@ -18,6 +18,7 @@ static CoverageTracker()
_markers = new Dictionary<string, List<string>>();
_markerFileCount = new Dictionary<string, int>();
AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_ProcessExit);
}

[ExcludeFromCoverage]
Expand Down Expand Up @@ -48,17 +49,22 @@ public static void MarkExecuted(string path, string marker)
[ExcludeFromCoverage]
public static void CurrentDomain_ProcessExit(object sender, EventArgs e)
{
foreach (var kvp in _markers)
lock (_markers)
{
using (var fs = new FileStream($"{kvp.Key}_compressed_{_markerFileCount[kvp.Key]}", FileMode.OpenOrCreate))
using (var gz = new GZipStream(fs, CompressionMode.Compress))
using (var sw = new StreamWriter(gz))
foreach (var kvp in _markers)
{
foreach(var line in kvp.Value)
using (var fs = new FileStream($"{kvp.Key}_compressed_{_markerFileCount[kvp.Key]}", FileMode.OpenOrCreate))
using (var gz = new GZipStream(fs, CompressionMode.Compress))
using (var sw = new StreamWriter(gz))
{
sw.WriteLine(line);
foreach(var line in kvp.Value)
{
sw.WriteLine(line);
}
}
}

_markers.Clear();
}
}
}
Expand Down

0 comments on commit 2d21f93

Please sign in to comment.