From 61bc18fee3402f5949645eeb54e77dfa7470775d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ros?= <sebastienros@gmail.com> Date: Fri, 1 Feb 2019 17:57:47 -0800 Subject: [PATCH] Exclude benchmark apps from builds (#7171) --- build/repo.props | 8 + src/Mvc/benchmarkapps/Directory.Build.props | 5 + src/Mvc/benchmarkapps/Directory.Build.targets | 3 + .../BasicApiTest.cs | 223 ------------------ .../BasicViewsTest.cs | 83 ------- .../Infrastructure/BasicApiFixture.cs | 21 -- .../Infrastructure/BasicViewsFixture.cs | 21 -- ...soft.AspNetCore.Mvc.FunctionalTests.csproj | 2 - .../PlatformBenchmarks/Directory.Build.props | 5 + .../Directory.Build.targets | 3 + .../PlatformBenchmarks.csproj | 8 +- .../perf/benchmarkapps/Directory.Build.props | 5 + .../benchmarkapps/Directory.Build.targets | 3 + 13 files changed, 35 insertions(+), 355 deletions(-) create mode 100644 src/Mvc/benchmarkapps/Directory.Build.props create mode 100644 src/Mvc/benchmarkapps/Directory.Build.targets delete mode 100644 src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicApiTest.cs delete mode 100644 src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicViewsTest.cs delete mode 100644 src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/BasicApiFixture.cs delete mode 100644 src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/BasicViewsFixture.cs create mode 100644 src/Servers/Kestrel/perf/PlatformBenchmarks/Directory.Build.props create mode 100644 src/Servers/Kestrel/perf/PlatformBenchmarks/Directory.Build.targets create mode 100644 src/SignalR/perf/benchmarkapps/Directory.Build.props create mode 100644 src/SignalR/perf/benchmarkapps/Directory.Build.targets diff --git a/build/repo.props b/build/repo.props index 19384ac9965..397e3d471d3 100644 --- a/build/repo.props +++ b/build/repo.props @@ -60,6 +60,14 @@ $(RepositoryRoot)src\ProjectTemplates\Web.ProjectTemplates\content\**\*.csproj; $(RepositoryRoot)src\ProjectTemplates\Web.Spa.ProjectTemplates\content\**\*.csproj; " /> + + <!-- Exclude the benchmarks because they use <PackageReference>. --> + <ProjectToExclude Include=" + $(RepositoryRoot)src\Mvc\benchmarkapps\**\*.csproj; + $(RepositoryRoot)src\Servers\Kestrel\perf\PlatformBenchmarks\**\*.csproj; + $(RepositoryRoot)src\SignalR\perf\benchmarkapps\**\*.csproj; + " /> + </ItemGroup> <Choose> diff --git a/src/Mvc/benchmarkapps/Directory.Build.props b/src/Mvc/benchmarkapps/Directory.Build.props new file mode 100644 index 00000000000..56a40aaa38b --- /dev/null +++ b/src/Mvc/benchmarkapps/Directory.Build.props @@ -0,0 +1,5 @@ +<Project> + + <Import Project="$(MSBuildThisFileDirectory)..\..\..\build\sources.props" /> + +</Project> \ No newline at end of file diff --git a/src/Mvc/benchmarkapps/Directory.Build.targets b/src/Mvc/benchmarkapps/Directory.Build.targets new file mode 100644 index 00000000000..2e3fb2fa713 --- /dev/null +++ b/src/Mvc/benchmarkapps/Directory.Build.targets @@ -0,0 +1,3 @@ +<!-- This file prevents any other Directory.Build.targets from a parent folder to be loaded --> +<Project> +</Project> \ No newline at end of file diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicApiTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicApiTest.cs deleted file mode 100644 index 42d2a5a5ce6..00000000000 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicApiTest.cs +++ /dev/null @@ -1,223 +0,0 @@ -// 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.Net; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Net.Http.Headers; -using Xunit; - -namespace Microsoft.AspNetCore.Mvc.FunctionalTests -{ - public class BasicApiTest : IClassFixture<BasicApiFixture> - { - private static readonly byte[] PetBytes = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false) - .GetBytes(@"{ - ""category"" : { - ""name"" : ""Cats"" - }, - ""images"": [ - { - ""url"": ""http://example.com/images/fluffy1.png"" - }, - { - ""url"": ""http://example.com/images/fluffy2.png"" - }, - ], - ""tags"": [ - { - ""name"": ""orange"" - }, - { - ""name"": ""kitty"" - } - ], - ""age"": 2, - ""hasVaccinations"": ""true"", - ""name"" : ""fluffy"", - ""status"" : ""available"" -}"); - - public BasicApiTest(BasicApiFixture fixture) - { - Client = fixture.CreateClient(); - } - - public HttpClient Client { get; } - - [Fact] - public async Task Token_WithUnknownUser_ReturnsForbidden() - { - // Arrange & Act - var response = await Client.GetAsync("/token?username=fallguy@example.com"); - - // Assert - Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); - } - - [Fact] - public async Task Token_WithKnownUser_ReturnsOkAndToken() - { - // Arrange & Act - var response = await Client.GetAsync("/token?username=reader@example.com"); - - // Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal("text/plain", response.Content.Headers.ContentType.MediaType); - - var token = await response.Content.ReadAsStringAsync(); - Assert.NotNull(token); - Assert.NotEmpty(token); - } - - [Fact] - public async Task FindByStatus_WithNoToken_ReturnsUnauthorized() - { - // Arrange & Act - var response = await Client.GetAsync("/pet/findByStatus?status=available"); - - // Assert - Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); - } - - [Theory] - [InlineData("reader@example.com")] - [InlineData("writer@example.com")] - public async Task FindByStatus_WithToken_ReturnsOkAndPet(string username) - { - // Arrange & Act 1 - var token = await Client.GetStringAsync($"/token?username={username}"); - - // Assert 1 (guard) - Assert.NotEmpty(token); - - // Arrange 2 - var request = new HttpRequestMessage(HttpMethod.Get, "/pet/findByStatus?status=available"); - request.Headers.Add(HeaderNames.Authorization, $"Bearer {token}"); - - // Act 2 - var response = await Client.SendAsync(request); - - // Assert 2 - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal("application/json", response.Content.Headers.ContentType.MediaType); - - var json = await response.Content.ReadAsStringAsync(); - Assert.NotNull(json); - Assert.NotEmpty(json); - } - - [Fact] - public async Task FindById_WithInvalidPetId_ReturnsNotFound() - { - // Arrange & Act 1 - var token = await Client.GetStringAsync("/token?username=reader@example.com"); - - // Assert 1 (guard) - Assert.NotEmpty(token); - - // Arrange 2 - var request = new HttpRequestMessage(HttpMethod.Get, "/pet/100"); - request.Headers.Add(HeaderNames.Authorization, $"Bearer {token}"); - - // Act 2 - var response = await Client.SendAsync(request); - - // Assert 2 - Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); - } - - [Fact] - public async Task FindById_WithValidPetId_ReturnsOkAndPet() - { - // Arrange & Act 1 - var token = await Client.GetStringAsync("/token?username=reader@example.com"); - - // Assert 1 (guard) - Assert.NotEmpty(token); - - // Arrange 2 - var request = new HttpRequestMessage(HttpMethod.Get, "/pet/-1"); - request.Headers.Add(HeaderNames.Authorization, $"Bearer {token}"); - - // Act 2 - var response = await Client.SendAsync(request); - - // Assert 2 - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal("application/json", response.Content.Headers.ContentType.MediaType); - - var json = await response.Content.ReadAsStringAsync(); - Assert.NotNull(json); - Assert.NotEmpty(json); - } - - [Fact] - public async Task AddPet_WithInsufficientClaims_ReturnsForbidden() - { - // Arrange & Act 1 - var token = await Client.GetStringAsync("/token?username=reader@example.com"); - - // Assert 1 (guard) - Assert.NotEmpty(token); - - // Arrange 2 - var request = new HttpRequestMessage(HttpMethod.Post, "/pet") - { - Content = new ByteArrayContent(PetBytes) - { - Headers = - { - { "Content-Type", "application/json" }, - }, - }, - Headers = - { - { HeaderNames.Authorization, $"Bearer {token}" }, - }, - }; - - // Act 2 - var response = await Client.SendAsync(request); - - // Assert 2 - Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); - } - - [Fact] - public async Task AddPet_WithValidClaims_ReturnsCreated() - { - // Arrange & Act 1 - var token = await Client.GetStringAsync("/token?username=writer@example.com"); - - // Assert 1 (guard) - Assert.NotEmpty(token); - - // Arrange 2 - var request = new HttpRequestMessage(HttpMethod.Post, "/pet") - { - Content = new ByteArrayContent(PetBytes) - { - Headers = - { - { HeaderNames.ContentType, "application/json" }, - }, - }, - Headers = - { - { HeaderNames.Authorization, $"Bearer {token}" }, - }, - }; - - // Act 2 - var response = await Client.SendAsync(request); - - // Assert 2 - Assert.Equal(HttpStatusCode.Created, response.StatusCode); - var location = response.Headers.Location.ToString(); - Assert.NotNull(location); - Assert.EndsWith("/1", location); - } - } -} diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicViewsTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicViewsTest.cs deleted file mode 100644 index 5f9b0bbcd8b..00000000000 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicViewsTest.cs +++ /dev/null @@ -1,83 +0,0 @@ -// 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.Collections.Generic; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; -using Xunit; - -namespace Microsoft.AspNetCore.Mvc.FunctionalTests -{ - public class BasicViewsTest : IClassFixture<BasicViewsFixture> - { - public BasicViewsTest(BasicViewsFixture fixture) - { - Client = fixture.CreateClient(); - } - - public HttpClient Client { get; } - - [Theory] - [InlineData("/")] - [InlineData("/Home/HtmlHelpers")] - public async Task Get_ReturnsOkAndAntiforgeryToken(string path) - { - // Arrange & Act - var response = await Client.GetAsync(path); - - // Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal("text/html", response.Content.Headers.ContentType.MediaType); - - var html = await response.Content.ReadAsStringAsync(); - Assert.NotNull(html); - Assert.NotEmpty(html); - - var token = AntiforgeryTestHelper.RetrieveAntiforgeryToken(html, "/"); - Assert.NotNull(token); - Assert.NotEmpty(token); - } - - [Theory] - [InlineData("/")] - [InlineData("/Home/HtmlHelpers")] - public async Task Post_ReturnsOkAndNewPerson(string path) - { - // Arrange & Act 1 - var html = await Client.GetStringAsync(path); - - // Assert 1 (guard) - Assert.NotEmpty(html); - - // Arrange 2 - var token = AntiforgeryTestHelper.RetrieveAntiforgeryToken(html, "/"); - var name = Guid.NewGuid().ToString(); - name = name.Substring(startIndex: 0, length: name.LastIndexOf('-')); - var form = new Dictionary<string, string> - { - { "__RequestVerificationToken", token }, - { "Age", "12" }, - { "BirthDate", "2006-03-01T09:51:43.041-07:00" }, - { "Name", name }, - }; - - var content = new FormUrlEncodedContent(form); - var request = new HttpRequestMessage(HttpMethod.Post, path) - { - Content = content, - }; - - // Act 2 - var response = await Client.SendAsync(request); - - // Assert 2 - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - - var body = await response.Content.ReadAsStringAsync(); - Assert.NotNull(body); - Assert.Contains($@"value=""{name}""", body); - } - } -} diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/BasicApiFixture.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/BasicApiFixture.cs deleted file mode 100644 index 56294311a7e..00000000000 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/BasicApiFixture.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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 BasicApi; - -namespace Microsoft.AspNetCore.Mvc.FunctionalTests -{ - public class BasicApiFixture : MvcTestFixture<Startup> - { - // Do not leave .db file behind. Also, ensure added pet gets expected id (1) in subsequent runs. - protected override void Dispose(bool disposing) - { - if (disposing) - { - Startup.DropDatabase(Server.Host.Services); - } - - base.Dispose(disposing); - } - } -} diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/BasicViewsFixture.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/BasicViewsFixture.cs deleted file mode 100644 index 3ea0c60835a..00000000000 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/BasicViewsFixture.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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 BasicViews; - -namespace Microsoft.AspNetCore.Mvc.FunctionalTests -{ - public class BasicViewsFixture : MvcTestFixture<Startup> - { - // Do not leave .db file behind. - protected override void Dispose(bool disposing) - { - if (disposing) - { - Startup.DropDatabase(Server.Host.Services); - } - - base.Dispose(disposing); - } - } -} diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj b/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj index 8df756d388e..34afae6bb9b 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj @@ -26,8 +26,6 @@ <ItemGroup> <Reference Include="Microsoft.AspNetCore.Mvc.Testing" /> - <ProjectReference Include="..\..\benchmarkapps\BasicApi\BasicApi.csproj" /> - <ProjectReference Include="..\..\benchmarkapps\BasicViews\BasicViews.csproj" /> <ProjectReference Include="..\..\samples\MvcSandbox\MvcSandbox.csproj" /> <ProjectReference Include="..\Microsoft.AspNetCore.Mvc.Core.TestCommon\Microsoft.AspNetCore.Mvc.Core.TestCommon.csproj" /> diff --git a/src/Servers/Kestrel/perf/PlatformBenchmarks/Directory.Build.props b/src/Servers/Kestrel/perf/PlatformBenchmarks/Directory.Build.props new file mode 100644 index 00000000000..7bd80027279 --- /dev/null +++ b/src/Servers/Kestrel/perf/PlatformBenchmarks/Directory.Build.props @@ -0,0 +1,5 @@ +<Project> + + <Import Project="$(MSBuildThisFileDirectory)..\..\..\..\..\build\sources.props" /> + +</Project> \ No newline at end of file diff --git a/src/Servers/Kestrel/perf/PlatformBenchmarks/Directory.Build.targets b/src/Servers/Kestrel/perf/PlatformBenchmarks/Directory.Build.targets new file mode 100644 index 00000000000..2e3fb2fa713 --- /dev/null +++ b/src/Servers/Kestrel/perf/PlatformBenchmarks/Directory.Build.targets @@ -0,0 +1,3 @@ +<!-- This file prevents any other Directory.Build.targets from a parent folder to be loaded --> +<Project> +</Project> \ No newline at end of file diff --git a/src/Servers/Kestrel/perf/PlatformBenchmarks/PlatformBenchmarks.csproj b/src/Servers/Kestrel/perf/PlatformBenchmarks/PlatformBenchmarks.csproj index 78041dec70e..ba82850bbc7 100644 --- a/src/Servers/Kestrel/perf/PlatformBenchmarks/PlatformBenchmarks.csproj +++ b/src/Servers/Kestrel/perf/PlatformBenchmarks/PlatformBenchmarks.csproj @@ -9,12 +9,9 @@ <IsTestAssetProject>true</IsTestAssetProject> </PropertyGroup> - <ItemGroup> - <Reference Include="Utf8Json" /> - </ItemGroup> - <!-- These references are used when running locally --> <ItemGroup Condition="'$(BenchmarksTargetFramework)' == ''"> + <Reference Include="Utf8Json" /> <Reference Include="Microsoft.AspNetCore.Server.Kestrel" /> <Reference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" /> @@ -23,7 +20,8 @@ <!-- These references are used when running on the Benchmarks Server --> <ItemGroup Condition="'$(BenchmarksTargetFramework)' != ''"> - <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" version="2.2.0" /> + <PackageReference Include="Utf8Json" Version="1.3.7" /> + <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" Version="2.2.0" /> <KnownFrameworkReference Update="Microsoft.AspNetCore.App" DefaultRuntimeFrameworkVersion="$(MicrosoftAspNetCoreAppPackageVersion)" diff --git a/src/SignalR/perf/benchmarkapps/Directory.Build.props b/src/SignalR/perf/benchmarkapps/Directory.Build.props new file mode 100644 index 00000000000..25cdcade1c3 --- /dev/null +++ b/src/SignalR/perf/benchmarkapps/Directory.Build.props @@ -0,0 +1,5 @@ +<Project> + + <Import Project="$(MSBuildThisFileDirectory)..\..\..\..\build\sources.props" /> + +</Project> \ No newline at end of file diff --git a/src/SignalR/perf/benchmarkapps/Directory.Build.targets b/src/SignalR/perf/benchmarkapps/Directory.Build.targets new file mode 100644 index 00000000000..2e3fb2fa713 --- /dev/null +++ b/src/SignalR/perf/benchmarkapps/Directory.Build.targets @@ -0,0 +1,3 @@ +<!-- This file prevents any other Directory.Build.targets from a parent folder to be loaded --> +<Project> +</Project> \ No newline at end of file -- GitLab