Modified integration test infrastructure to test build server

This commit is contained in:
Ajay Bhargav Baaskaran 2018-01-29 01:09:11 -08:00
parent b677a9e43f
commit 9244383ec7
16 changed files with 137 additions and 22 deletions

View File

@ -13,9 +13,6 @@
<_RazorTagHelperInputCache>$(IntermediateOutputPath)$(TargetName).TagHelpers.input.cache</_RazorTagHelperInputCache>
<_RazorTagHelperOutputCache>$(IntermediateOutputPath)$(TargetName).TagHelpers.output.cache</_RazorTagHelperOutputCache>
<!-- Used to locate our tools -->
<_RazorToolAssembly>$(_RazorMSBuildRoot)tools\rzc.dll</_RazorToolAssembly>
<!-- Used to hash file inputs for RazorGenerate -->
<_RazorGenerateInputsHash></_RazorGenerateInputsHash>
<_RazorGenerateInputsHashFile>$(IntermediateOutputPath)$(MSBuildProjectName).RazorCoreGenerate.cache</_RazorGenerateInputsHashFile>
@ -74,6 +71,7 @@
DebugTool="$(_RazorDebugTagHelperTool)"
ToolAssembly="$(_RazorToolAssembly)"
UseServer="$(UseRazorBuildServer)"
PipeName="$(_RazorBuildServerPipeName)"
Assemblies="@(RazorReferencePath)"
ProjectRoot="$(MSBuildProjectDirectory)"
TagHelperManifest="$(_RazorTagHelperOutputCache)">
@ -116,6 +114,7 @@
DebugTool="$(_RazorDebugGenerateCodeTool)"
ToolAssembly="$(_RazorToolAssembly)"
UseServer="$(UseRazorBuildServer)"
PipeName="$(_RazorBuildServerPipeName)"
Sources="@(RazorGenerate)"
ProjectRoot="$(MSBuildProjectDirectory)"
TagHelperManifest="$(_RazorTagHelperOutputCache)"

View File

@ -20,6 +20,9 @@
<_RazorTaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core' ">net46</_RazorTaskFolder>
<_RazorTaskAssembly Condition="'$(_RazorTaskAssembly)'==''">$(_RazorMSBuildRoot)\tasks\$(_RazorTaskFolder)\Microsoft.AspNetCore.Razor.Tasks.dll</_RazorTaskAssembly>
<!-- Used to locate our tools -->
<_RazorToolAssembly Condition="'$(_RazorToolAssembly)'==''">$(_RazorMSBuildRoot)tools\rzc.dll</_RazorToolAssembly>
</PropertyGroup>
<UsingTask TaskName="Microsoft.AspNetCore.Razor.Tasks.RazorGenerate" AssemblyFile="$(_RazorTaskAssembly)" />

View File

@ -38,6 +38,8 @@ Copyright (c) .NET Foundation. All rights reserved.
or publish-time. By default, the Razor SDK will suppress the copying of reference assemblies to the publish directory.
-->
<CopyRefAssembliesToPublishDirectory Condition="'$(CopyRefAssembliesToPublishDirectory)'==''">false</CopyRefAssembliesToPublishDirectory>
<UseRazorBuildServer Condition="'$(UseRazorBuildServer)'==''">false</UseRazorBuildServer>
</PropertyGroup>
</Project>

View File

@ -72,8 +72,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- Default to on if MvcRazorCompileOnPublish isn't set for some reason -->
<RazorCompileOnPublish Condition="'$(RazorCompileOnPublish)'==''">true</RazorCompileOnPublish>
<UseRazorBuildServer Condition="'$(UseRazorBuildServer)'==''">false</UseRazorBuildServer>
</PropertyGroup>
<!--

View File

@ -29,6 +29,8 @@ namespace Microsoft.AspNetCore.Razor.Tasks
public bool UseServer { get; set; }
public string PipeName { get; set; }
protected override string ToolName => "dotnet";
// If we're debugging then make all of the stdout gets logged in MSBuild
@ -130,7 +132,7 @@ namespace Microsoft.AspNetCore.Razor.Tasks
var arguments = GetArguments(responseFileCommands);
var responseTask = ServerConnection.RunOnServer(arguments, serverPaths, _razorServerCts.Token);
var responseTask = ServerConnection.RunOnServer(PipeName, arguments, serverPaths, _razorServerCts.Token);
responseTask.Wait(_razorServerCts.Token);
var response = responseTask.Result;

View File

@ -29,4 +29,14 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Mvc.Razor.Extensions\Microsoft.AspNetCore.Mvc.Razor.Extensions.csproj" />
</ItemGroup>
<!-- This makes it so that the runtimeconfig.json is included as part of the build output of the project that references this project. -->
<Target Name="PreserveRuntimeConfig" BeforeTargets="GetCopyToOutputDirectoryItems">
<ItemGroup>
<AllItemsFullPathWithTargetPath Include="$(ProjectRuntimeConfigFilePath)">
<TargetPath>$(ProjectRuntimeConfigFileName)</TargetPath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</AllItemsFullPathWithTargetPath>
</ItemGroup>
</Target>
</Project>

View File

@ -4,5 +4,6 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Razor.Tools.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Razor.Design.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]

View File

@ -83,12 +83,16 @@ namespace Microsoft.AspNetCore.Razor.Tools
}
public static Task<ServerResponse> RunOnServer(
string pipeName,
List<string> arguments,
ServerPaths buildPaths,
CancellationToken cancellationToken,
string keepAlive = null)
{
var pipeName = PipeName.ComputeDefault();
if (string.IsNullOrEmpty(pipeName))
{
pipeName = PipeName.ComputeDefault();
}
return RunOnServerCore(
arguments,
@ -244,7 +248,8 @@ namespace Microsoft.AspNetCore.Razor.Tools
}
}
private static bool TryCreateServerCore(string clientDir, string pipeName)
// Internal for testing.
internal static bool TryCreateServerCore(string clientDir, string pipeName)
{
string expectedPath;
string processArguments;

View File

@ -5,7 +5,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
{
internal static partial class BuildVariables
{
private static string _msBuildPath = "";
private static string _msBuildPath = string.Empty;
static partial void InitializeVariables();

View File

@ -0,0 +1,39 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using System.Threading.Tasks;
using Microsoft.DotNet.PlatformAbstractions;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
{
public class BuildServerIntegrationTest : MSBuildIntegrationTestBase, IClassFixture<BuildServerTestFixture>
{
private readonly string _pipeName;
public BuildServerIntegrationTest(BuildServerTestFixture fixture)
{
_pipeName = fixture.PipeName;
}
[Fact]
[InitializeTestProject("SimpleMvc")]
public Task Build_SimpleMvc_WithServer_UsingDotnetMSBuild_CanBuildSuccessfully()
=> Build_SimpleMvc_CanBuildSuccessfully(MSBuildProcessKind.Dotnet);
private async Task Build_SimpleMvc_CanBuildSuccessfully(MSBuildProcessKind msBuildProcessKind)
{
var result = await DotnetMSBuild(
"Build",
$"/p:RazorCompileOnBuild=true /p:UseRazorBuildServer=true /p:_RazorBuildServerPipeName={_pipeName}",
msBuildProcessKind: msBuildProcessKind);
Assert.BuildPassed(result);
Assert.FileExists(result, OutputPath, "SimpleMvc.dll");
Assert.FileExists(result, OutputPath, "SimpleMvc.pdb");
Assert.FileExists(result, OutputPath, "SimpleMvc.PrecompiledViews.dll");
Assert.FileExists(result, OutputPath, "SimpleMvc.PrecompiledViews.pdb");
}
}
}

View File

@ -0,0 +1,61 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Threading;
using Microsoft.AspNetCore.Razor.Tools;
namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
{
public class BuildServerTestFixture : IDisposable
{
private static readonly TimeSpan _defaultShutdownTimeout = TimeSpan.FromSeconds(60);
public BuildServerTestFixture()
{
PipeName = Guid.NewGuid().ToString();
if (!ServerConnection.TryCreateServerCore(Environment.CurrentDirectory, PipeName))
{
throw new InvalidOperationException($"Failed to start the build server at pipe {PipeName}.");
}
}
public string PipeName { get; }
public void Dispose()
{
// Shutdown the build server.
using (var cts = new CancellationTokenSource(_defaultShutdownTimeout))
{
cts.Token.Register(() =>
{
throw new TimeoutException($"Shutting down the build server at pipe {PipeName} took longer than expected.");
});
var application = new Application(cts.Token);
var exitCode = application.Execute("shutdown", "-w", "-p", PipeName);
if (exitCode != 0)
{
var output = application.Error.ToString();
throw new InvalidOperationException(
$"Build server at pipe {PipeName} failed to shutdown with exit code {exitCode}. Output: {output}");
}
}
}
private static string RecursiveFind(string path, string start)
{
var test = Path.Combine(start, path);
if (File.Exists(test))
{
return start;
}
else
{
return RecursiveFind(path, new DirectoryInfo(start).Parent.FullName);
}
}
}
}

View File

@ -1,12 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
{
internal enum MSBuildProcessKind

View File

@ -49,9 +49,9 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
StartInfo = processStartInfo,
EnableRaisingEvents = true,
};
var output = new StringBuilder();
process.ErrorDataReceived += Process_ErrorDataReceived;
process.OutputDataReceived += Process_OutputDataReceived;

View File

@ -3,7 +3,6 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;

View File

@ -42,12 +42,11 @@
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Razor.Design\Microsoft.AspNetCore.Razor.Design.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Razor.Tools\Microsoft.AspNetCore.Razor.Tools.csproj" />
</ItemGroup>
<Target Name="EnsureBuildVariablesGeneratedFile">
<Error
Text="BuildVariables.generated.cs was not found. Run .\build /t:Prepare from the root of the repository to generate it."
Condition="!Exists('$(BuildVariablesGeneratedFile)')" />
<Error Text="BuildVariables.generated.cs was not found. Run .\build /t:Prepare from the root of the repository to generate it." Condition="!Exists('$(BuildVariablesGeneratedFile)')" />
</Target>
</Project>

View File

@ -155,7 +155,10 @@ namespace Microsoft.AspNetCore.Razor.Tools
/// <summary>
/// Multiple clients should be able to send shutdown requests to the server.
/// </summary>
[Fact]
// Skipping temporarily on non-windows. https://github.com/aspnet/Razor/issues/1991
[ConditionalFact]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task ServerRunning_MultipleShutdownRequests_HandlesSuccessfully()
{
// Arrange