Skip to content
Merged
Changes from 1 commit
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
16 changes: 14 additions & 2 deletions src/Build.UnitTests/BackEnd/TaskBuilder_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -144,10 +145,11 @@ 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>";

Expand All @@ -168,8 +170,18 @@ public void CanceledTasksDoNotLogMSB4181()
BuildRequestData data = new BuildRequestData(project.CreateProjectInstance(), new string[] { "test" }, collection.HostServices);
manager.BeginBuild(_parameters);
BuildSubmission asyncResult = manager.PendBuildRequest(data);
string unescapedSleepCommand = sleepCommand.Replace("&quot;", "\"").Replace("&gt;", ">");
Func<bool> isSleepCommandExecuted = () => logger.AllBuildEvents.Any(a => unescapedSleepCommand.Equals(a.Message));
Task waitCommandExecuted = new Task(() =>
{
while (!isSleepCommandExecuted())
{
Task.Delay(TimeSpan.FromMilliseconds(10)).Wait();
}
});
asyncResult.ExecuteAsync(null, null);
Thread.Sleep(500);
waitCommandExecuted.Start();
waitCommandExecuted.Wait(TimeSpan.FromSeconds(5)).ShouldBeTrue("Waiting for executing the command timed out.");
manager.CancelAllSubmissions();
asyncResult.WaitHandle.WaitOne();
BuildResult result = asyncResult.BuildResult;
Expand Down