Skip to content

Commit 8ca3acd

Browse files
Wait on task loop in case of exception (#45237)
1 parent 211390f commit 8ca3acd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,38 +97,38 @@ public int Run(ParseResult parseResult)
9797
if (msbuildResult != 0)
9898
{
9999
VSTestTrace.SafeWriteTrace(() => $"MSBuild task _GetTestsProject didn't execute properly with exit code: {msbuildResult}.");
100-
CleanUp();
101100
return ExitCodes.GenericFailure;
102101
}
103102

104103
// If not all test projects have IsTestingPlatformApplication set to true, we will simply return
105104
if (!_msBuildConnectionHandler.EnqueueTestApplications())
106105
{
107106
VSTestTrace.SafeWriteTrace(() => LocalizableStrings.CmdUnsupportedVSTestTestApplicationsDescription);
108-
CleanUp();
109107
return ExitCodes.GenericFailure;
110108
}
111109
}
112110

113111
_actionQueue.EnqueueCompleted();
114112
hasFailed = _actionQueue.WaitAllActions();
115-
116113
// Above line will block till we have all connections and all GetTestsProject msbuild task complete.
117-
_cancellationToken.Cancel();
118-
_namedPipeConnectionLoop.Wait();
119114

120-
// Clean up everything
121-
CleanUp();
115+
WaitOnMSBuildHandlerPipeConnectionLoop();
122116
}
123-
catch (Exception)
117+
finally
124118
{
119+
// Clean up everything
125120
CleanUp();
126-
throw;
127121
}
128122

129123
return hasFailed ? ExitCodes.GenericFailure : ExitCodes.Success;
130124
}
131125

126+
private void WaitOnMSBuildHandlerPipeConnectionLoop()
127+
{
128+
_cancellationToken.Cancel();
129+
_namedPipeConnectionLoop.Wait((int)TimeSpan.FromSeconds(30).TotalMilliseconds);
130+
}
131+
132132
private void CleanUp()
133133
{
134134
_msBuildConnectionHandler.Dispose();

0 commit comments

Comments
 (0)