Skip to content

Commit ab567ad

Browse files
committed
fix failing asyncawait issue
1 parent ec5e637 commit ab567ad

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.IO;
5+
using System.Reflection;
56
using System.Threading;
67
using System.Threading.Tasks;
78
using Coverlet.Core.Samples.Tests;
@@ -99,34 +100,35 @@ public void AsyncAwait_Issue_669_1()
99100
}
100101
}
101102

102-
//[Fact]
103-
//public void AsyncAwait_Issue_669_2()
104-
//{
105-
// string path = Path.GetTempFileName();
106-
// try
107-
// {
108-
// FunctionExecutor.Run(async (string[] pathSerialize) =>
109-
// {
110-
// CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Issue_669_2>(instance =>
111-
// {
112-
// ((ValueTask<System.Net.Http.HttpResponseMessage>)instance.SendRequest()).ConfigureAwait(false).GetAwaiter().GetResult();
113-
// return Task.CompletedTask;
114-
// },
115-
// persistPrepareResultToFile: pathSerialize[0]);
116-
117-
// return 0;
118-
// }, new string[] { path });
119-
120-
// TestInstrumentationHelper.GetCoverageResult(path)
121-
// .Document("Instrumentation.AsyncAwait.cs")
122-
// .AssertLinesCovered(BuildConfiguration.Debug, (7, 1), (10, 1), (11, 1), (12, 1), (13, 1), (15, 1))
123-
// .ExpectedTotalNumberOfBranches(BuildConfiguration.Debug, 0);
124-
// }
125-
// finally
126-
// {
127-
// File.Delete(path);
128-
// }
129-
//}
103+
[Fact]
104+
public void AsyncAwait_Issue_669_2()
105+
{
106+
string path = Path.GetTempFileName();
107+
try
108+
{
109+
FunctionExecutor.Run(async (string[] pathSerialize) =>
110+
{
111+
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Issue_669_2>(instance =>
112+
{
113+
((ValueTask<System.Net.Http.HttpResponseMessage>)instance.SendRequest()).ConfigureAwait(false).GetAwaiter().GetResult();
114+
return Task.CompletedTask;
115+
},
116+
persistPrepareResultToFile: pathSerialize[0],
117+
assemblyLocation: Assembly.GetExecutingAssembly().Location);
118+
119+
return 0;
120+
}, new string[] { path });
121+
122+
TestInstrumentationHelper.GetCoverageResult(path)
123+
.Document("Instrumentation.AsyncAwait.cs")
124+
.AssertLinesCovered(BuildConfiguration.Debug, (7, 1), (10, 1), (11, 1), (12, 1), (13, 1), (15, 1))
125+
.ExpectedTotalNumberOfBranches(BuildConfiguration.Debug, 0);
126+
}
127+
finally
128+
{
129+
File.Delete(path);
130+
}
131+
}
130132

131133
[Fact]
132134
public void AsyncAwait_Issue_1177()

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public static async Task<CoveragePrepareResult> Run<T>(Func<dynamic, Task> callM
7676
Func<string, string[]> doesNotReturnAttributes = null,
7777
string persistPrepareResultToFile = null,
7878
bool disableRestoreModules = false,
79-
bool skipAutoProps = false)
79+
bool skipAutoProps = false,
80+
string assemblyLocation = null)
8081
{
8182
if (persistPrepareResultToFile is null)
8283
{
@@ -92,8 +93,9 @@ public static async Task<CoveragePrepareResult> Run<T>(Func<dynamic, Task> callM
9293
File.Copy(location, newPath);
9394
File.Copy(Path.ChangeExtension(location, ".pdb"), Path.ChangeExtension(newPath, ".pdb"));
9495

95-
SetTestContainer(newPath, disableRestoreModules);
96-
96+
string sourceRootTranslatorModulePath = assemblyLocation ?? newPath;
97+
SetTestContainer(sourceRootTranslatorModulePath, disableRestoreModules);
98+
9799
static string[] defaultFilters(string _) => Array.Empty<string>();
98100

99101
var parameters = new CoverageParameters

0 commit comments

Comments
 (0)