From 18b92c3829237390e73e57ea0c83c2df6d69c0e8 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Fri, 12 Jul 2024 00:07:52 -0400 Subject: [PATCH] merge from playground branch --- .../Aspire.Components.Common.Tests.csproj | 2 ++ .../Aspire.EndToEnd.Tests.csproj | 1 + .../StarterTemplateRunTestsBase.cs | 2 -- .../WorkloadTestsBase.cs | 7 ++-- tests/Directory.Build.props | 2 ++ tests/Directory.Build.targets | 5 ++- tests/Shared/Aspire.Workload.Testing.props | 2 +- tests/Shared/Logging/XunitLoggerProvider.cs | 2 +- .../RepoTesting/Aspire.Testing.Repo.targets | 33 ++++++++++++++++++- tests/Shared/WorkloadTesting/AspireProject.cs | 17 ++++++---- .../WorkloadTesting/EnvironmentVariables.cs | 1 + tests/Shared/WorkloadTesting/ProjectInfo.cs | 6 ++-- tests/Shared/WorkloadTesting/ResourceRow.cs | 6 ++++ .../data/Directory.Packages.Helix.props | 16 +++++---- tests/helix/send-to-helix-inner.proj | 6 ++-- 15 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 tests/Shared/WorkloadTesting/ResourceRow.cs diff --git a/tests/Aspire.Components.Common.Tests/Aspire.Components.Common.Tests.csproj b/tests/Aspire.Components.Common.Tests/Aspire.Components.Common.Tests.csproj index 3302f811074..93576a6f2a3 100644 --- a/tests/Aspire.Components.Common.Tests/Aspire.Components.Common.Tests.csproj +++ b/tests/Aspire.Components.Common.Tests/Aspire.Components.Common.Tests.csproj @@ -3,6 +3,8 @@ $(NetCurrent) true + + true diff --git a/tests/Aspire.EndToEnd.Tests/Aspire.EndToEnd.Tests.csproj b/tests/Aspire.EndToEnd.Tests/Aspire.EndToEnd.Tests.csproj index 38ec4341f09..59a45e06506 100644 --- a/tests/Aspire.EndToEnd.Tests/Aspire.EndToEnd.Tests.csproj +++ b/tests/Aspire.EndToEnd.Tests/Aspire.EndToEnd.Tests.csproj @@ -11,6 +11,7 @@ true $(TestUsingWorkloads) + false true true xunit.runner.json diff --git a/tests/Aspire.Workload.Tests/StarterTemplateRunTestsBase.cs b/tests/Aspire.Workload.Tests/StarterTemplateRunTestsBase.cs index 0f7e71aa547..0c5d202edc9 100644 --- a/tests/Aspire.Workload.Tests/StarterTemplateRunTestsBase.cs +++ b/tests/Aspire.Workload.Tests/StarterTemplateRunTestsBase.cs @@ -139,5 +139,3 @@ public static List GetExpectedResources(AspireProject project, bool return expectedResources; } } - -public sealed record ResourceRow(string Type, string Name, string State, string Source, string[] Endpoints); diff --git a/tests/Aspire.Workload.Tests/WorkloadTestsBase.cs b/tests/Aspire.Workload.Tests/WorkloadTestsBase.cs index ad33d0eaedc..b613f922b59 100644 --- a/tests/Aspire.Workload.Tests/WorkloadTestsBase.cs +++ b/tests/Aspire.Workload.Tests/WorkloadTestsBase.cs @@ -137,8 +137,11 @@ protected static async Task CheckDashboardHasResourcesAsync(IPage AssertEqual(expectedEndpoints.Length, matchingEndpoints, $"Expected number of endpoints for {resourceName}"); - // Check 'Source' column - AssertEqual(expectedRow.Source, await cellLocs[4].InnerTextAsync(), $"Source for {resourceName}"); + if (expectedRow.Source is not null) + { + // Check 'Source' column + AssertEqual(expectedRow.Source, await cellLocs[4].InnerTextAsync(), $"Source for {resourceName}"); + } foundRows.Add(expectedRow with { Endpoints = endpointsFound.ToArray() }); foundNames.Add(resourceName); diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index e4717a3c5c6..008e1e7869f 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -8,8 +8,10 @@ $(RepositoryEngineeringDir)testing\.runsettings $([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'tests')) $([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'workload-tests')) + $([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'playground-tests')) $([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'e2e-tests')) $(ArtifactsBinDir)playwright-deps + $(IntermediateOutputPath)Directory.Packages.Versions.props $(ArtifactsTestResultsDir) diff --git a/tests/Directory.Build.targets b/tests/Directory.Build.targets index a475837c610..19df7972c6a 100644 --- a/tests/Directory.Build.targets +++ b/tests/Directory.Build.targets @@ -31,10 +31,9 @@ Overwrite="true" /> + - - - + <_PackageVersionEvaluated Include="@(PackageVersion -> '<PackageVersion Include="%(Identity)" Version="%(Version)" />')" /> diff --git a/tests/Shared/Aspire.Workload.Testing.props b/tests/Shared/Aspire.Workload.Testing.props index ecca432e065..bf3a3b52741 100644 --- a/tests/Shared/Aspire.Workload.Testing.props +++ b/tests/Shared/Aspire.Workload.Testing.props @@ -6,7 +6,7 @@ $(RepoRoot)NuGet.config $(ArtifactsObjDir)nuget.workload.config - $(ArtifactsObjDir)Directory.Packages.Versions.props + $(IntermediateOutputPath)Directory.Packages.Versions.props <_GlobalJsonContent>$([System.IO.File]::ReadAllText('$(RepoRoot)global.json')) <_DotNetCliVersionFromGlobalJson>$([System.Text.RegularExpressions.Regex]::Match($(_GlobalJsonContent), '(%3F<="dotnet": ").*(%3F=")')) diff --git a/tests/Shared/Logging/XunitLoggerProvider.cs b/tests/Shared/Logging/XunitLoggerProvider.cs index b08c94f5098..66176ed7bdc 100644 --- a/tests/Shared/Logging/XunitLoggerProvider.cs +++ b/tests/Shared/Logging/XunitLoggerProvider.cs @@ -7,7 +7,7 @@ namespace Microsoft.Extensions.Logging.Testing; -public class XunitLoggerProvider : ILoggerProvider +public sealed class XunitLoggerProvider : ILoggerProvider { private readonly ITestOutputHelper _output; private readonly LogLevel _minLevel; diff --git a/tests/Shared/RepoTesting/Aspire.Testing.Repo.targets b/tests/Shared/RepoTesting/Aspire.Testing.Repo.targets index acbec448bfb..f72805932f2 100644 --- a/tests/Shared/RepoTesting/Aspire.Testing.Repo.targets +++ b/tests/Shared/RepoTesting/Aspire.Testing.Repo.targets @@ -5,7 +5,13 @@ when running in the repo. --> + true + + true $(IntermediateOutputPath)Directory.Packages.Versions.props + staging-for-archive\ + $([MSBuild]::EnsureTrailingSlash('$(RelativeStagingDir)')) + $(TestArchiveTestsDirForPlaygroundTests) @@ -30,7 +36,25 @@ - + + + + + + + + + + + + + + + + + + + @@ -40,9 +64,16 @@ + TESTS_RUNNING_OUTSIDE_OF_REPO;$(DefineConstants) + + + $(OutDir)$(RelativeStagingDir) + + + diff --git a/tests/Shared/WorkloadTesting/AspireProject.cs b/tests/Shared/WorkloadTesting/AspireProject.cs index e005dfa2146..84b1e51b997 100644 --- a/tests/Shared/WorkloadTesting/AspireProject.cs +++ b/tests/Shared/WorkloadTesting/AspireProject.cs @@ -27,7 +27,7 @@ public static string GetNuGetConfigPathFor(string targetFramework) => public string Id { get; init; } public string RootDir { get; init; } public string LogPath { get; init; } - public string AppHostProjectDirectory => Path.Combine(RootDir, $"{Id}.AppHost"); + public string AppHostProjectDirectory { get; init; } public string ServiceDefaultsProjectPath => Path.Combine(RootDir, $"{Id}.ServiceDefaults"); public string TestsProjectDirectory => Path.Combine(RootDir, $"{Id}.Tests"); public string? DashboardUrl { get; private set; } @@ -38,13 +38,14 @@ public static string GetNuGetConfigPathFor(string targetFramework) => private readonly ITestOutputHelper _testOutput; private readonly BuildEnvironment _buildEnv; - public AspireProject(string id, string baseDir, ITestOutputHelper testOutput, BuildEnvironment buildEnv) + public AspireProject(string id, string baseDir, ITestOutputHelper testOutput, BuildEnvironment buildEnv, string? relativeAppHostProjectDir = null) { Id = id; RootDir = baseDir; _testOutput = testOutput; _buildEnv = buildEnv; LogPath = Path.Combine(_buildEnv.LogRootPath, Id); + AppHostProjectDirectory = relativeAppHostProjectDir ?? Path.Combine(RootDir, $"{Id}.AppHost"); } protected void InitPaths() @@ -102,7 +103,11 @@ public static async Task CreateNewTemplateProjectAsync(string id, return project; } - public async Task StartAppHostAsync(string[]? extraArgs = default, Action? configureProcess = null, bool noBuild = true, CancellationToken token = default) + public async Task StartAppHostAsync(string[]? extraArgs = default, + Action? configureProcess = null, + bool noBuild = true, + bool expectEndpointsHook = true, + CancellationToken token = default) { if (IsRunning) { @@ -207,7 +212,7 @@ public async Task StartAppHostAsync(string[]? extraArgs = default, Action HttpGetStringAsync(string bindingName, string path, Cancella { var allocatedEndpoint = Endpoints.Single(e => e.Name == bindingName); var url = $"{allocatedEndpoint.Uri}{path}"; + System.Console.WriteLine($"HttpGetStringAsync: {url}"); return Client.GetStringAsync(url, cancellationToken); } - public async Task WaitForHealthyStatusAsync(string bindingName, ITestOutputHelper testOutput, CancellationToken cancellationToken = default) + public async Task WaitForHealthyStatusAsync(string bindingName, ITestOutputHelper testOutput, string path = "/health", CancellationToken cancellationToken = default) { while (true) { try { - var status = await HttpGetStringAsync(bindingName, "/health", cancellationToken); + var status = await HttpGetStringAsync(bindingName, path, cancellationToken); + System.Console.WriteLine($"{path} returned {status}"); if (status == "Healthy") { return; diff --git a/tests/Shared/WorkloadTesting/ResourceRow.cs b/tests/Shared/WorkloadTesting/ResourceRow.cs new file mode 100644 index 00000000000..9ed04e5d46b --- /dev/null +++ b/tests/Shared/WorkloadTesting/ResourceRow.cs @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Aspire.Workload.Tests; + +public sealed record ResourceRow(string Type, string Name, string State, string? Source, string[] Endpoints); diff --git a/tests/Shared/WorkloadTesting/data/Directory.Packages.Helix.props b/tests/Shared/WorkloadTesting/data/Directory.Packages.Helix.props index b96110c1336..c869279784d 100644 --- a/tests/Shared/WorkloadTesting/data/Directory.Packages.Helix.props +++ b/tests/Shared/WorkloadTesting/data/Directory.Packages.Helix.props @@ -79,11 +79,15 @@ - - - - - - + + + + + + + + + + diff --git a/tests/helix/send-to-helix-inner.proj b/tests/helix/send-to-helix-inner.proj index fcf66eb4baa..d084536b507 100644 --- a/tests/helix/send-to-helix-inner.proj +++ b/tests/helix/send-to-helix-inner.proj @@ -25,9 +25,6 @@ <_SupportDataStagingDir>$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'support-data')) _StageDotNetCoverageTool;_StageCreateDotNetDevCertScripts - - - true @@ -40,6 +37,9 @@ <_TestNameEnvVar Condition="'$(OS)' != 'Windows_NT'">${TEST_NAME} <_TestNameEnvVar Condition="'$(OS)' == 'Windows_NT'">%TEST_NAME% + <_TestAssemblyRootDirEnvVar Condition="'$(OS)' != 'Windows_NT'">${HELIX_WORKITEM_ROOT} + <_TestAssemblyRootDirEnvVar Condition="'$(OS)' == 'Windows_NT'">%HELIX_WORKITEM_ROOT% + <_CodeCoverageReportFileNameSuffixEnvVar Condition="'$(OS)' != 'Windows_NT'">${CODE_COV_FILE_SUFFIX} <_CodeCoverageReportFileNameSuffixEnvVar Condition="'$(OS)' == 'Windows_NT'">%CODE_COV_FILE_SUFFIX%