Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use distinct signal to wait to cancel the submission #9326

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Build.UnitTests/BackEnd/TaskBuilder_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,24 @@ public void CanceledTasksDoNotLogMSB4181()
BuildManager manager = new BuildManager();
ProjectCollection collection = new ProjectCollection();

string sleepCommand = Helpers.GetSleepCommand(TimeSpan.FromSeconds(10));
string contents = @"
<Project ToolsVersion ='Current'>
<Target Name='test'>
<Exec Command='" + Helpers.GetSleepCommand(TimeSpan.FromSeconds(10)) + @"'/>
<Exec Command='" + sleepCommand + @"'/>
</Target>
</Project>";

MockLogger logger = new MockLogger(_testOutput);
ManualResetEvent waitCommandExecuted = new ManualResetEvent(false);
string unescapedSleepCommand = sleepCommand.Replace("&quot;", "\"").Replace("&gt;", ">");
logger.AdditionalHandlers.Add((sender, args) =>
{
if (unescapedSleepCommand.Equals(args.Message))
{
waitCommandExecuted.Set();
}
});

var project = new Project(XmlReader.Create(new StringReader(contents)), null, MSBuildConstants.CurrentToolsVersion, collection)
{
Expand All @@ -169,7 +179,7 @@ public void CanceledTasksDoNotLogMSB4181()
manager.BeginBuild(_parameters);
BuildSubmission asyncResult = manager.PendBuildRequest(data);
asyncResult.ExecuteAsync(null, null);
Thread.Sleep(500);
waitCommandExecuted.WaitOne();
GangWang01 marked this conversation as resolved.
Show resolved Hide resolved
manager.CancelAllSubmissions();
asyncResult.WaitHandle.WaitOne();
BuildResult result = asyncResult.BuildResult;
Expand Down