Skip to content

Commit

Permalink
fix failing asyncawait issue
Browse files Browse the repository at this point in the history
  • Loading branch information
daveMueller committed Mar 14, 2023
1 parent ec5e637 commit ab567ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
58 changes: 30 additions & 28 deletions test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Coverlet.Core.Samples.Tests;
Expand Down Expand Up @@ -99,34 +100,35 @@ public void AsyncAwait_Issue_669_1()
}
}

//[Fact]
//public void AsyncAwait_Issue_669_2()
//{
// string path = Path.GetTempFileName();
// try
// {
// FunctionExecutor.Run(async (string[] pathSerialize) =>
// {
// CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Issue_669_2>(instance =>
// {
// ((ValueTask<System.Net.Http.HttpResponseMessage>)instance.SendRequest()).ConfigureAwait(false).GetAwaiter().GetResult();
// return Task.CompletedTask;
// },
// persistPrepareResultToFile: pathSerialize[0]);

// return 0;
// }, new string[] { path });

// TestInstrumentationHelper.GetCoverageResult(path)
// .Document("Instrumentation.AsyncAwait.cs")
// .AssertLinesCovered(BuildConfiguration.Debug, (7, 1), (10, 1), (11, 1), (12, 1), (13, 1), (15, 1))
// .ExpectedTotalNumberOfBranches(BuildConfiguration.Debug, 0);
// }
// finally
// {
// File.Delete(path);
// }
//}
[Fact]
public void AsyncAwait_Issue_669_2()
{
string path = Path.GetTempFileName();
try
{
FunctionExecutor.Run(async (string[] pathSerialize) =>
{
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Issue_669_2>(instance =>
{
((ValueTask<System.Net.Http.HttpResponseMessage>)instance.SendRequest()).ConfigureAwait(false).GetAwaiter().GetResult();
return Task.CompletedTask;
},
persistPrepareResultToFile: pathSerialize[0],
assemblyLocation: Assembly.GetExecutingAssembly().Location);
return 0;
}, new string[] { path });

TestInstrumentationHelper.GetCoverageResult(path)
.Document("Instrumentation.AsyncAwait.cs")
.AssertLinesCovered(BuildConfiguration.Debug, (7, 1), (10, 1), (11, 1), (12, 1), (13, 1), (15, 1))
.ExpectedTotalNumberOfBranches(BuildConfiguration.Debug, 0);
}
finally
{
File.Delete(path);
}
}

[Fact]
public void AsyncAwait_Issue_1177()
Expand Down
8 changes: 5 additions & 3 deletions test/coverlet.core.tests/Coverage/InstrumenterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public static CoverageResult GetCoverageResult(string filePath)
Func<string, string[]> doesNotReturnAttributes = null,
string persistPrepareResultToFile = null,
bool disableRestoreModules = false,
bool skipAutoProps = false)
bool skipAutoProps = false,
string assemblyLocation = null)
{
if (persistPrepareResultToFile is null)
{
Expand All @@ -92,8 +93,9 @@ public static CoverageResult GetCoverageResult(string filePath)
File.Copy(location, newPath);
File.Copy(Path.ChangeExtension(location, ".pdb"), Path.ChangeExtension(newPath, ".pdb"));

SetTestContainer(newPath, disableRestoreModules);

string sourceRootTranslatorModulePath = assemblyLocation ?? newPath;
SetTestContainer(sourceRootTranslatorModulePath, disableRestoreModules);

static string[] defaultFilters(string _) => Array.Empty<string>();

var parameters = new CoverageParameters
Expand Down

0 comments on commit ab567ad

Please sign in to comment.