Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

<ItemGroup>
<Content Include="testassets\**\*" CopyToOutputDirectory="PreserveNewest" />
<Content Include="..\Microsoft.DotNet.Arcade.Sdk\tools\Tests.targets"
Link="testassets\ParallelTestTfms\Tests.targets"
CopyToOutputDirectory="PreserveNewest" />
<Content Include="$(RepositoryEngineeringDir)common\**\*" LinkBase="testassets\boilerplate\eng\common\" CopyToOutputDirectory="PreserveNewest" />
<Content Include="$(RepoRoot)build.sh" LinkBase="testassets\boilerplate\" CopyToOutputDirectory="PreserveNewest" />
<Content Include="$(RepoRoot)Build.cmd" LinkBase="testassets\boilerplate\" CopyToOutputDirectory="PreserveNewest" />
Expand Down
47 changes: 47 additions & 0 deletions src/Microsoft.DotNet.Arcade.Sdk.Tests/ParallelTestTfmsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.IO;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.DotNet.Arcade.Sdk.Tests
{
[Collection(TestProjectCollection.Name)]
public class ParallelTestTfmsTests
{
private readonly ITestOutputHelper _output;
private readonly TestProjectFixture _fixture;

public ParallelTestTfmsTests(ITestOutputHelper output, TestProjectFixture fixture)
{
_output = output;
_fixture = fixture;
}

[Fact]
public void TargetFrameworksRunInParallel()
{
var app = _fixture.CreateTestApp("ParallelTestTfms");
Directory.CreateDirectory(Path.Combine(app.WorkingDirectory, "artifacts", "log"));
var startInfo = new ProcessStartInfo
{
FileName = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet",
WorkingDirectory = app.WorkingDirectory,
};
startInfo.ArgumentList.Add("msbuild");
startInfo.ArgumentList.Add("ParallelTestTfms.proj");
startInfo.ArgumentList.Add("/t:Test");
startInfo.ArgumentList.Add("/m:4");
startInfo.ArgumentList.Add("/nr:false");

var exitCode = app.Run(_output, startInfo);

Assert.Equal(0, exitCode);
Assert.True(File.Exists(Path.Combine(app.WorkingDirectory, "artifacts", "tmp", "test-tfm-a.started")));
Assert.True(File.Exists(Path.Combine(app.WorkingDirectory, "artifacts", "tmp", "test-tfm-b.started")));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project>
<PropertyGroup>
<TargetFrameworks>test-tfm-a;test-tfm-b</TargetFrameworks>
<IsTestProject>true</IsTestProject>
<IsUnitTestProject>true</IsUnitTestProject>
<TestRunnerName>Parallel</TestRunnerName>
<RepositoryEngineeringDir>$(MSBuildThisFileDirectory)eng\</RepositoryEngineeringDir>
<TestRuntime>Core</TestRuntime>
<TestArchitectures>x64</TestArchitectures>
<TargetPath>$(MSBuildThisFileDirectory)$(TargetFramework)\ParallelTestTfms.dll</TargetPath>
<ArtifactsTmpDir>$(MSBuildThisFileDirectory)artifacts\tmp\</ArtifactsTmpDir>
<ArtifactsLogDir>$(MSBuildThisFileDirectory)artifacts\log\</ArtifactsLogDir>
<ArtifactsTestResultsDir>$(MSBuildThisFileDirectory)artifacts\TestResults\</ArtifactsTestResultsDir>
</PropertyGroup>
<Import Project="Tests.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<Project>
<UsingTask TaskName="WaitForFiles"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
<TimeoutSeconds ParameterType="System.Int32" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Linq" />
<Using Namespace="System.Threading" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var deadline = DateTime.UtcNow.AddSeconds(TimeoutSeconds);
while (Files.Any(file => !File.Exists(file.ItemSpec)))
Comment thread
Evangelink marked this conversation as resolved.
Outdated
{
if (DateTime.UtcNow >= deadline)
{
Log.LogError("Timed out waiting for all target frameworks to start.");
break;
}

Thread.Sleep(100);
}
]]>
</Code>
</Task>
</UsingTask>

<Target Name="ComputeRunArguments" />

<Target Name="RunTests"
Outputs="%(TestToRun.ResultsStdOutPath)"
Condition="'@(TestToRun)' != ''">
<PropertyGroup>
<_StartedFile>$(ArtifactsTmpDir)$(TargetFramework).started</_StartedFile>
</PropertyGroup>
<ItemGroup>
<_ExpectedStartedFile Include="$(ArtifactsTmpDir)test-tfm-a.started" />
<_ExpectedStartedFile Include="$(ArtifactsTmpDir)test-tfm-b.started" />
</ItemGroup>
<MakeDir Directories="$(ArtifactsTmpDir)" />
<WriteLinesToFile File="$(_StartedFile)" Lines="$(TargetFramework)" Overwrite="true" />
<WaitForFiles Files="@(_ExpectedStartedFile)" TimeoutSeconds="10" />
<ItemGroup>
<FileWrites Include="$(_StartedFile)" />
</ItemGroup>
</Target>
Comment thread
Evangelink marked this conversation as resolved.
</Project>
26 changes: 16 additions & 10 deletions src/Microsoft.DotNet.Arcade.Sdk/tools/Tests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<AutoGenerateBindingRedirects Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">true</AutoGenerateBindingRedirects>

<_GetTestsToRunTarget Condition="'$(TargetFrameworks)' == ''">_InnerGetTestsToRun</_GetTestsToRunTarget>
<_GetTestsToRunTarget Condition="'$(TargetFrameworks)' != ''">_OuterGetTestsToRun</_GetTestsToRunTarget>
<_RunTestsTarget Condition="'$(TargetFrameworks)' == ''">_InnerRunTests</_RunTestsTarget>
<_RunTestsTarget Condition="'$(TargetFrameworks)' != ''">_OuterRunTests</_RunTestsTarget>

<!-- The runtime to run tests on: 'Core', 'Mono', 'Full' (desktop FX). -->
<TestRuntime Condition="'$(TestRuntime)' == '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">Core</TestRuntime>
Expand All @@ -32,8 +32,8 @@
<TestArchitectures Condition="'$(PlatformTarget)' == '' or '$(PlatformTarget)' == 'AnyCpu'">x64</TestArchitectures>
</PropertyGroup>

<Target Name="Test" DependsOnTargets="ErrorForMissingTestRunner;$(_GetTestsToRunTarget);RunTests" Condition="'$(IsUnitTestProject)' == 'true' or '$(IsPerformanceTestProject)' == 'true'" />
<Target Name="IntegrationTest" DependsOnTargets="ErrorForMissingTestRunner;$(_GetTestsToRunTarget);RunTests" Condition="'$(IsIntegrationTestProject)' == 'true'" />
<Target Name="Test" DependsOnTargets="ErrorForMissingTestRunner;$(_RunTestsTarget)" Condition="'$(IsUnitTestProject)' == 'true' or '$(IsPerformanceTestProject)' == 'true'" />
<Target Name="IntegrationTest" DependsOnTargets="ErrorForMissingTestRunner;$(_RunTestsTarget)" Condition="'$(IsIntegrationTestProject)' == 'true'" />

<ItemGroup>
<_TestArchitectureItems Include="$(TestArchitectures)" />
Expand Down Expand Up @@ -78,15 +78,21 @@
</ItemGroup>
</Target>

<Target Name="_OuterGetTestsToRun" Returns="@(TestToRun)">
<Target Name="_InnerRunTests"
DependsOnTargets="_InnerGetTestsToRun;RunTests"
Returns="@(FileWrites)" />

<Target Name="_OuterRunTests" Returns="@(FileWrites)">
<ItemGroup>
<_TargetFramework Include="$(TargetFrameworks)" />
<_TargetFramework Project="$(MSBuildProjectFile)" />
<_InnerTestBuild Include="%(_TargetFramework.Project)"
AdditionalProperties="TargetFramework=%(_TargetFramework.Identity)" />
</ItemGroup>
Comment thread
Evangelink marked this conversation as resolved.
<MSBuild Projects="$(MSBuildProjectFile)"
Condition="'$(TargetFrameworks)' != ''"
Targets="_InnerGetTestsToRun"
Properties="TargetFramework=%(_TargetFramework.Identity)">
<Output ItemName="TestToRun" TaskParameter="TargetOutputs" />
<MSBuild Projects="@(_InnerTestBuild)"
Targets="_InnerRunTests"
BuildInParallel="true">
<Output ItemName="FileWrites" TaskParameter="TargetOutputs" />
</MSBuild>
</Target>

Expand Down
Loading