Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
4 changes: 2 additions & 2 deletions .vsts-dotnet-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ jobs:
arguments: --repoRoot $(Build.SourcesDirectory)
- task: PublishPipelineArtifact@1
displayName: Publish Code Coverage Results
continueOnError: false
continueOnError: true
condition: eq(variables.onlyDocChanged, 0)
inputs:
targetPath: '$(Build.SourcesDirectory)/artifacts/CoverageResults/merged.coverage'
Expand Down Expand Up @@ -468,7 +468,7 @@ jobs:
arguments: --repoRoot $(Build.SourcesDirectory)
- task: PublishPipelineArtifact@1
displayName: Publish Code Coverage Results
continueOnError: false
continueOnError: true
condition: eq(variables.onlyDocChanged, 0)
inputs:
targetPath: '$(Build.SourcesDirectory)/artifacts/CoverageResults/merged.coverage'
Expand Down
117 changes: 43 additions & 74 deletions src/Build.UnitTests/BackEnd/AssemblyTaskFactory_Tests.cs

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -997,8 +997,8 @@ public void TestTaskResolutionFailureWithUsingTask()
#endif
false,
CancellationToken.None);
_host.FindTask(null);
_host.InitializeForBatch(new TaskLoggingContext(_loggingService, tlc.BuildEventContext), _bucket, null, scheduledNodeId: 1);
_host.FindTask(TaskHostParameters.Empty);
_host.InitializeForBatch(new TaskLoggingContext(_loggingService, tlc.BuildEventContext), _bucket, TaskHostParameters.Empty, scheduledNodeId: 1);
});
}
/// <summary>
Expand Down Expand Up @@ -1026,8 +1026,8 @@ public void TestTaskResolutionFailureWithNoUsingTask()
false,
CancellationToken.None);

_host.FindTask(null);
_host.InitializeForBatch(new TaskLoggingContext(_loggingService, tlc.BuildEventContext), _bucket, null, scheduledNodeId: 1);
_host.FindTask(TaskHostParameters.Empty);
_host.InitializeForBatch(new TaskLoggingContext(_loggingService, tlc.BuildEventContext), _bucket, TaskHostParameters.Empty, scheduledNodeId: 1);
_logger.AssertLogContains("MSB4036");
}

Expand Down Expand Up @@ -1254,7 +1254,7 @@ private void InitializeHost(bool throwOnExecute)
TaskBuilderTestTask.TaskBuilderTestTaskFactory taskFactory = new TaskBuilderTestTask.TaskBuilderTestTaskFactory();
taskFactory.ThrowOnExecute = throwOnExecute;
string taskName = "TaskBuilderTestTask";
(_host as TaskExecutionHost)._UNITTESTONLY_TaskFactoryWrapper = new TaskFactoryWrapper(taskFactory, loadedType, taskName, null);
(_host as TaskExecutionHost)._UNITTESTONLY_TaskFactoryWrapper = new TaskFactoryWrapper(taskFactory, loadedType, taskName, TaskHostParameters.Empty);
_host.InitializeForTask(
this,
tlc,
Expand Down Expand Up @@ -1289,8 +1289,8 @@ private void InitializeHost(bool throwOnExecute)

_bucket = new ItemBucket(FrozenSet<string>.Empty, new Dictionary<string, string>(), new Lookup(itemsByName, new PropertyDictionary<ProjectPropertyInstance>()), 0);
_bucket.Initialize(null);
_host.FindTask(null);
_host.InitializeForBatch(talc, _bucket, null, scheduledNodeId: 1);
_host.FindTask(TaskHostParameters.Empty);
_host.InitializeForBatch(talc, _bucket, TaskHostParameters.Empty, scheduledNodeId: 1);
_parametersSetOnTask = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
_outputsReadFromTask = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
}
Expand Down
67 changes: 52 additions & 15 deletions src/Build.UnitTests/BackEnd/TaskHostFactory_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.UnitTests;
Expand All @@ -23,6 +25,8 @@ namespace Microsoft.Build.Engine.UnitTests.BackEnd
/// </summary>
public sealed class TaskHostFactory_Tests
{
private static string AssemblyLocation { get; } = Path.Combine(Path.GetDirectoryName(typeof(TaskHostFactory_Tests).Assembly.Location) ?? AppContext.BaseDirectory, "Microsoft.Build.Engine.UnitTests.dll");

private ITestOutputHelper _output;

public TaskHostFactory_Tests(ITestOutputHelper testOutputHelper)
Expand All @@ -39,7 +43,7 @@ public TaskHostFactory_Tests(ITestOutputHelper testOutputHelper)
/// <param name="envVariableSpecified">Whether to set MSBUILDFORCEALLTASKSOUTOFPROC environment variable</param>
[Theory]
[InlineData(true, false)]
[InlineData(false, true, Skip = "floating failure, it requires separate investigation")]
[InlineData(false, true)]
[InlineData(true, true)]
public void TaskNodesDieAfterBuild(bool taskHostFactorySpecified, bool envVariableSpecified)
{
Expand All @@ -48,7 +52,7 @@ public void TaskNodesDieAfterBuild(bool taskHostFactorySpecified, bool envVariab
string taskFactory = taskHostFactorySpecified ? "TaskHostFactory" : "AssemblyTaskFactory";
string pidTaskProject = $@"
<Project>
<UsingTask TaskName=""ProcessIdTask"" AssemblyName=""Microsoft.Build.Engine.UnitTests"" TaskFactory=""{taskFactory}"" />
<UsingTask TaskName=""ProcessIdTask"" AssemblyFile=""{AssemblyLocation}"" TaskFactory=""{taskFactory}"" />
<Target Name='AccessPID'>
<ProcessIdTask>
<Output PropertyName=""PID"" TaskParameter=""Pid"" />
Expand Down Expand Up @@ -93,11 +97,44 @@ public void TaskNodesDieAfterBuild(bool taskHostFactorySpecified, bool envVariab
}
else
{
// This is the sidecar TaskHost case - it should persist after build is done. So we need to clean up and kill it ourselves.
Process taskHostNode = Process.GetProcessById(pid);

// This is the sidecar TaskHost case - it should persist after build is done. So we need to clean up and kill it ourselves.
// Wait for process to be responsive. The standard 3 secs can be not enough for the child process to start, let's try several times.
int attempts = 0;
while (attempts < 5)
{
try
{
if (taskHostNode.HasExited)
{
Assert.Fail($"TaskHost exited during startup with code: {taskHostNode.ExitCode}");
}

// Check if process has loaded its main module
if (taskHostNode.Modules.Count > 0)
{
break;
}
}
catch
{
// Process not ready yet
}

Thread.Sleep(1000);
attempts++;
taskHostNode.Refresh();
}

// Now wait to ensure it stays alive
bool processExited = taskHostNode.WaitForExit(3000);

processExited.ShouldBeFalse();
processExited.ShouldBeFalse(
processExited
? $"TaskHost should remain alive after build. TaskHost exited with code: {taskHostNode.ExitCode}"
: "TaskHost should remain alive after build for task host case.");

try
{
taskHostNode.Kill();
Expand All @@ -121,17 +158,17 @@ public void TransientAndSidecarNodeCanCoexist()
{
string pidTaskProject = $@"
<Project>
<UsingTask TaskName=""ProcessIdTask"" AssemblyName=""Microsoft.Build.Engine.UnitTests"" TaskFactory=""TaskHostFactory"" />
<UsingTask TaskName=""ProcessIdTaskSidecar"" AssemblyName=""Microsoft.Build.Engine.UnitTests"" TaskFactory=""AssemblyTaskFactory"" />

<Target Name='AccessPID'>
<ProcessIdTask>
<Output PropertyName=""PID"" TaskParameter=""Pid"" />
</ProcessIdTask>
<ProcessIdTaskSidecar>
<Output PropertyName=""PID2"" TaskParameter=""Pid"" />
</ProcessIdTaskSidecar>
</Target>
<UsingTask TaskName=""ProcessIdTask"" AssemblyFile=""{AssemblyLocation}"" TaskFactory=""TaskHostFactory"" />
<UsingTask TaskName=""ProcessIdTaskSidecar"" AssemblyFile=""{AssemblyLocation}"" TaskFactory=""AssemblyTaskFactory"" />

<Target Name='AccessPID'>
<ProcessIdTask>
<Output PropertyName=""PID"" TaskParameter=""Pid"" />
</ProcessIdTask>
<ProcessIdTaskSidecar>
<Output PropertyName=""PID2"" TaskParameter=""Pid"" />
</ProcessIdTaskSidecar>
</Target>
</Project>";

TransientTestFile project = env.CreateFile("testProject.csproj", pidTaskProject);
Expand Down
Loading