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 all 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
19 changes: 16 additions & 3 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,11 +179,14 @@ public void CanceledTasksDoNotLogMSB4181()
manager.BeginBuild(_parameters);
BuildSubmission asyncResult = manager.PendBuildRequest(data);
asyncResult.ExecuteAsync(null, null);
Thread.Sleep(500);
int timeoutMilliseconds = 2000;
bool isCommandExecuted = waitCommandExecuted.WaitOne(timeoutMilliseconds);
manager.CancelAllSubmissions();
asyncResult.WaitHandle.WaitOne();
bool isSubmissionComplated = asyncResult.WaitHandle.WaitOne(timeoutMilliseconds);
BuildResult result = asyncResult.BuildResult;
manager.EndBuild();
isCommandExecuted.ShouldBeTrue($"Waiting for that the sleep command is executed failed in the timeout period {timeoutMilliseconds} ms.");
isSubmissionComplated.ShouldBeTrue($"Waiting for that the build submission is completed failed in the timeout period {timeoutMilliseconds} ms.");

// No errors from cancelling a build.
logger.ErrorCount.ShouldBe(0);
Expand Down