Skip to content
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