Skip to content

Commit e3e0ff9

Browse files
committed
TestExecutionCancelAndFinished && !cancelling. RunAsync Action for tests
1 parent 0c0ef08 commit e3e0ff9

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

FineCodeCoverageTests/TestContainerDiscovery_Tests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public void SetUp()
6262
{
6363
mocker = new AutoMoqer();
6464
var testContainerDiscoverer = mocker.Create<TestContainerDiscoverer>();
65+
testContainerDiscoverer.RunAsync = (taskProvider) =>
66+
{
67+
taskProvider().Wait();
68+
};
6569
testContainerDiscoverer.initializeThread.Join();
6670
}
6771

SharedProject/Impl/TestContainerDiscovery/TestContainerDiscoverer.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ IReportGeneratorUtil reportGeneratorUtil
6565

6666
}
6767

68+
internal Action<Func<System.Threading.Tasks.Task>> RunAsync = (taskProvider) =>
69+
{
70+
_ = ThreadHelper.JoinableTaskFactory.RunAsync(taskProvider);
71+
};
72+
6873
private async System.Threading.Tasks.Task TestExecutionStartingAsync(IOperation operation)
6974
{
7075
fccEngine.StopCoverage();
@@ -125,15 +130,16 @@ private async System.Threading.Tasks.Task TestExecutionFinishedAsync(IOperation
125130
}
126131
fccEngine.ReloadCoverage(testOperation.GetCoverageProjectsAsync);
127132
}
128-
133+
private bool cancelling;
129134
private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e)
130135
{
131-
_ = ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
136+
RunAsync(async () =>
132137
{
133138
try
134139
{
135140
if (e.State == TestOperationStates.TestExecutionCanceling)
136141
{
142+
cancelling = true;
137143
await CombinedLogAsync("Test execution cancelling - running coverage will be cancelled.");
138144
await reportGeneratorUtil.EndOfCoverageRunAsync(); // not necessarily true but get desired result
139145
fccEngine.StopCoverage();
@@ -143,19 +149,21 @@ private void OperationState_StateChanged(object sender, OperationStateChangedEve
143149
if (e.State == TestOperationStates.TestExecutionStarting)
144150
{
145151
await TestExecutionStartingAsync(e.Operation);
152+
cancelling = false;
146153
}
147154

148155
if (e.State == TestOperationStates.TestExecutionFinished)
149156
{
150157
await TestExecutionFinishedAsync(e.Operation);
151158
}
152159

153-
if (e.State == TestOperationStates.TestExecutionCancelAndFinished)
160+
if (e.State == TestOperationStates.TestExecutionCancelAndFinished && !cancelling)
154161
{
155162
await CombinedLogAsync("There has been an issue running tests. See the Tests output window pane.");
156163
await reportGeneratorUtil.EndOfCoverageRunAsync(); // not necessarily true but get desired result
157-
fccEngine.StopCoverage();
164+
fccEngine.StopCoverage();
158165
}
166+
159167
}
160168
catch (Exception exception)
161169
{

0 commit comments

Comments
 (0)