Skip to content

Commit

Permalink
merge from playground branch
Browse files Browse the repository at this point in the history
  • Loading branch information
radical committed Jul 12, 2024
1 parent e23cd4c commit 18b92c3
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<IsTestSupportProject>true</IsTestSupportProject>

<IncludeTestPackages Condition="'$(TestsRunningOutsideOfRepo)' == 'true'">true</IncludeTestPackages>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions tests/Aspire.EndToEnd.Tests/Aspire.EndToEnd.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<TestUsingWorkloads Condition="! ('$(ContinuousIntegrationBuild)' == 'true' and '$(OS)' == 'Windows_NT')">true</TestUsingWorkloads>
<InstallWorkloadForTesting>$(TestUsingWorkloads)</InstallWorkloadForTesting>

<IncludeTestPackages>false</IncludeTestPackages>
<SupportsRunningOutsideOfRepo>true</SupportsRunningOutsideOfRepo>
<TestsRunningOutsideOfRepo Condition="'$(TestsRunningOutsideOfRepo)' == '' and '$(ContinuousIntegrationBuild)' == 'true'">true</TestsRunningOutsideOfRepo>
<XunitRunnerJson>xunit.runner.json</XunitRunnerJson>
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.Workload.Tests/StarterTemplateRunTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,3 @@ public static List<ResourceRow> GetExpectedResources(AspireProject project, bool
return expectedResources;
}
}

public sealed record ResourceRow(string Type, string Name, string State, string Source, string[] Endpoints);
7 changes: 5 additions & 2 deletions tests/Aspire.Workload.Tests/WorkloadTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ protected static async Task<ResourceRow[]> 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);
Expand Down
2 changes: 2 additions & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
<RunSettingsFilePath>$(RepositoryEngineeringDir)testing\.runsettings</RunSettingsFilePath>
<TestArchiveTestsDir Condition="'$(TestArchiveTestsDir)' == ''">$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'tests'))</TestArchiveTestsDir>
<TestArchiveTestsDirForWorkloadTests Condition="'$(TestArchiveTestsDirForWorkloadTests)' == ''">$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'workload-tests'))</TestArchiveTestsDirForWorkloadTests>
<TestArchiveTestsDirForPlaygroundTests Condition="'$(TestArchiveTestsDirForPlaygroundTests)' == ''">$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'playground-tests'))</TestArchiveTestsDirForPlaygroundTests>
<TestArchiveTestsDirForEndToEndTests Condition="'$(TestArchiveTestsDirForEndToEndTests)' == ''">$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'e2e-tests'))</TestArchiveTestsDirForEndToEndTests>
<PlaywrightDependenciesDirectory>$(ArtifactsBinDir)playwright-deps</PlaywrightDependenciesDirectory>
<GeneratedPackagesVersionsPropsPath>$(IntermediateOutputPath)Directory.Packages.Versions.props</GeneratedPackagesVersionsPropsPath>

<!-- This is useful for local runs -->
<VSTestResultsDirectory>$(ArtifactsTestResultsDir)</VSTestResultsDirectory>
Expand Down
5 changes: 2 additions & 3 deletions tests/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
Overwrite="true" />
</Target>

<!-- move to .. repo.targets?? -->
<!-- generate before the build so the project can use this in a <None ..> item -->
<Target Name="_GeneratePackagesVersionsProps" BeforeTargets="BeforeBuild" Condition="'$(SupportsRunningOutsideOfRepo)' == 'true' and '$(TestsRunningOutsideOfRepo)' != 'true'">
<!-- FIXME: what should the condition be? Introduce a "supports tests running.. ? -->
<!--Condition="'$(ArchiveTests)' == 'true' or '$(TestsRunningOutsideOfRepo)' == 'true'" -->
<Target Name="_GeneratePackagesVersionsProps" BeforeTargets="BeforeBuild" Condition="'$(SupportsRunningOutsideOfRepo)' == 'true'">
<!-- Duplicate all the @(PackageVersion) items with the evaluated versions -->
<ItemGroup>
<_PackageVersionEvaluated Include="@(PackageVersion -> '&lt;PackageVersion Include=&quot;%(Identity)&quot; Version=&quot;%(Version)&quot; /&gt;')" />
Expand Down
2 changes: 1 addition & 1 deletion tests/Shared/Aspire.Workload.Testing.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<InstallWorkloadUsingArtifactsAfterThisTarget />
<TemplateNuGetConfigPath>$(RepoRoot)NuGet.config</TemplateNuGetConfigPath>
<PatchedNuGetConfigPath>$(ArtifactsObjDir)nuget.workload.config</PatchedNuGetConfigPath>
<GeneratedPackagesVersionsPropsPath>$(ArtifactsObjDir)Directory.Packages.Versions.props</GeneratedPackagesVersionsPropsPath>
<GeneratedPackagesVersionsPropsPath>$(IntermediateOutputPath)Directory.Packages.Versions.props</GeneratedPackagesVersionsPropsPath>

<_GlobalJsonContent>$([System.IO.File]::ReadAllText('$(RepoRoot)global.json'))</_GlobalJsonContent>
<_DotNetCliVersionFromGlobalJson>$([System.Text.RegularExpressions.Regex]::Match($(_GlobalJsonContent), '(%3F&lt;="dotnet": ").*(%3F=")'))</_DotNetCliVersionFromGlobalJson>
Expand Down
2 changes: 1 addition & 1 deletion tests/Shared/Logging/XunitLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 32 additions & 1 deletion tests/Shared/RepoTesting/Aspire.Testing.Repo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
when running in the repo. -->

<PropertyGroup>
<SupportsRunningOutsideOfRepo Condition="'$(SupportsRunningOutsideOfRepo)' == '' and '$(IsHostingTestingProject)' == 'true'">true</SupportsRunningOutsideOfRepo>

<IncludeTestPackages Condition="'$(IncludeTestPackages)' == '' and ('$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true')">true</IncludeTestPackages>
<GeneratedPackagesVersionsPropsPath>$(IntermediateOutputPath)Directory.Packages.Versions.props</GeneratedPackagesVersionsPropsPath>
<RelativeStagingDir Condition="'$(RelativeStagingDir)' == '' and '$(SupportsRunningOutsideOfRepo)' == 'true'">staging-for-archive\</RelativeStagingDir>
<RelativeStagingDir>$([MSBuild]::EnsureTrailingSlash('$(RelativeStagingDir)'))</RelativeStagingDir>
<TestArchiveTestsDir Condition="'$(SupportsRunningOutsideOfRepo)' == 'true'">$(TestArchiveTestsDirForPlaygroundTests)</TestArchiveTestsDir>
</PropertyGroup>

<ItemGroup Condition="'$(TestsRunningOutsideOfRepo)' != 'true'">
Expand All @@ -30,7 +36,25 @@
<PackageReference Include="Microsoft.DotNet.XUnitAssert" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(ArchiveTests)' == 'true' and '$(SupportsRunningOutsideOfRepo)' == 'true' and '$(IsTestProject)' == 'true'">
<!-- needed to isolate the build -->
<None Include="$(TestsSharedDir)EmptyProject.proj" Link="$(RelativeStagingDir)Directory.Build.props" CopyToOutputDirectory="PreserveNewest" />
<None Include="$(TestsSharedDir)EmptyProject.proj" Link="$(RelativeStagingDir)Directory.Build.targets" CopyToOutputDirectory="PreserveNewest" />
<None Include="$(TestsSharedRepoTestingDir)\*" Link="$(RelativeStagingDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />

<None Include="$(GeneratedPackagesVersionsPropsPath)" Link="$(RelativeStagingDir)Directory.Packages.Versions.props" CopyToOutputDirectory="PreserveNewest" />

<None Include="$(TestsSharedDir)nuget-with-package-source-mapping.config" Link="$(RelativeStagingDir)nuget.config" CopyToOutputDirectory="PreserveNewest" />

<!-- FIXME: move this file to out-of-repo? -->
<None Include="$(TestsSharedDir)WorkloadTesting\data\Directory.Packages.Helix.props" Link="$(RelativeStagingDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />

<!-- FIXME: should this be in the test project?? -->
<None Include="$(TestsSharedDir)\**\*" Link="staging-for-archive\tests\Shared\%(RecursiveDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup Condition="'$(SupportsRunningOutsideOfRepo)' == 'true'">
<PropertyForHelixRun Include="NetCurrent" />
<PropertyForHelixRun Include="XunitVersion" />
<PropertyForHelixRun Include="XunitAnalyzersVersion" />
<PropertyForHelixRun Include="XunitRunnerVisualStudioVersion" />
Expand All @@ -40,9 +64,16 @@
</ItemGroup>

<PropertyGroup>
<!-- this is for the main test project itself -->
<DefineConstants Condition="'$(TestsRunningOutsideOfRepo)' == 'true'">TESTS_RUNNING_OUTSIDE_OF_REPO;$(DefineConstants)</DefineConstants>
</PropertyGroup>

<Target Name="_UpdateArchiveSourcePath" BeforeTargets="ZipTestArchive" Condition="'$(ArchiveTests)' == 'true'">
<PropertyGroup>
<TestsArchiveSourceDir>$(OutDir)$(RelativeStagingDir)</TestsArchiveSourceDir>
</PropertyGroup>
</Target>

<ImportGroup Condition="'$(RepoRoot)' != 'null' and '$(TestsRunningOutsideOfRepo)' != 'true' and '$(IsAspireHost)' == 'true'">
<Import Project="$(RepoRoot)src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.targets" Condition="Exists('$(RepoRoot)src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.targets')" />
<Import Project="$(RepoRoot)src\Aspire.Hosting.Sdk\SDK\Sdk.targets" Condition="Exists('$(RepoRoot)src\Aspire.Hosting.Sdk\SDK\Sdk.targets')" />
Expand Down
17 changes: 11 additions & 6 deletions tests/Shared/WorkloadTesting/AspireProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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()
Expand Down Expand Up @@ -102,7 +103,11 @@ public static async Task<AspireProject> CreateNewTemplateProjectAsync(string id,
return project;
}

public async Task StartAppHostAsync(string[]? extraArgs = default, Action<ProcessStartInfo>? configureProcess = null, bool noBuild = true, CancellationToken token = default)
public async Task StartAppHostAsync(string[]? extraArgs = default,
Action<ProcessStartInfo>? configureProcess = null,
bool noBuild = true,
bool expectEndpointsHook = true,
CancellationToken token = default)
{
if (IsRunning)
{
Expand Down Expand Up @@ -207,7 +212,7 @@ public async Task StartAppHostAsync(string[]? extraArgs = default, Action<Proces
AppHostProcess.BeginOutputReadLine();
AppHostProcess.BeginErrorReadLine();

var successfulStartupTask = Task.WhenAll(appRunning.Task, projectsParsed.Task);
var successfulStartupTask = Task.WhenAll(appRunning.Task, expectEndpointsHook ? projectsParsed.Task : Task.CompletedTask);
var startupTimeoutTask = Task.Delay(TimeSpan.FromSeconds(AppStartupWaitTimeoutSecs), token);

string outputMessage;
Expand Down Expand Up @@ -264,7 +269,7 @@ public async Task StartAppHostAsync(string[]? extraArgs = default, Action<Proces
public async Task BuildAsync(string[]? extraBuildArgs = default, CancellationToken token = default)
{
using var restoreCmd = new DotNetCommand(_testOutput, buildEnv: _buildEnv, label: "restore")
.WithWorkingDirectory(Path.Combine(RootDir, $"{Id}.AppHost"));
.WithWorkingDirectory(AppHostProjectDirectory);
var res = await restoreCmd.ExecuteAsync($"restore \"-bl:{Path.Combine(LogPath!, $"{Id}-restore.binlog")}\" /p:TreatWarningsAsErrors=true");
res.EnsureSuccessful();

Expand All @@ -274,7 +279,7 @@ public async Task BuildAsync(string[]? extraBuildArgs = default, CancellationTok
buildArgs += " " + string.Join(" ", extraBuildArgs);
}
using var buildCmd = new DotNetCommand(_testOutput, buildEnv: _buildEnv, label: "build")
.WithWorkingDirectory(Path.Combine(RootDir, $"{Id}.AppHost"));
.WithWorkingDirectory(AppHostProjectDirectory);
res = await buildCmd.ExecuteAsync(buildArgs);
res.EnsureSuccessful();
}
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/WorkloadTesting/EnvironmentVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static class EnvironmentVariables
public static readonly bool TestsRunningOutsideOfRepo = Environment.GetEnvironmentVariable("TestsRunningOutsideOfRepo") is "true";
public static readonly string BuildConfiguration = Environment.GetEnvironmentVariable("BUILD_CONFIGURATION") ?? "Debug";
public static readonly string? TestAssetsPath = Environment.GetEnvironmentVariable("TEST_ASSETS_PATH");
public static readonly string? PlaygroundAppsPath = Environment.GetEnvironmentVariable("PLAYGROUND_APPS_PATH");
public static readonly string? TestScenario = Environment.GetEnvironmentVariable("TEST_SCENARIO");
public static readonly string? BrowserPath = Environment.GetEnvironmentVariable(PlaywrightProvider.BrowserPathEnvironmentVariableName);
}
6 changes: 4 additions & 2 deletions tests/Shared/WorkloadTesting/ProjectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ public Task<string> 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;
Expand Down
6 changes: 6 additions & 0 deletions tests/Shared/WorkloadTesting/ResourceRow.cs
Original file line number Diff line number Diff line change
@@ -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);
16 changes: 10 additions & 6 deletions tests/Shared/WorkloadTesting/data/Directory.Packages.Helix.props
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@
</ItemGroup>

<ItemGroup Label="For tests">
<PackageVersion Include="xunit" Version="$(XunitPackageVersion)" />
<PackageVersion Include="xunit.assert" Version="$(XunitPackageVersion)" />
<PackageVersion Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualStudioPackageVersion)" />
<PackageVersion Include="xunit.runner.console" Version="$(XunitPackageVersion)" />
<PackageVersion Include="mstest.testadapter" Version="$(MSTestTestAdapterPackageVersion)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" />
<PackageVersion Include="xunit" Version="$(XunitVersion)" />
<PackageVersion Include="xunit.core" Version="$(XunitVersion)" />
<PackageVersion Include="xunit.analyzers" Version="$(XunitAnalyzersVersion)" />
<PackageVersion Include="xunit.assert" Version="$(XunitVersion)" />
<PackageVersion Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualStudioVersion)" />
<PackageVersion Include="xunit.runner.console" Version="$(XunitVersion)" />

<PackageVersion Include="mstest.testadapter" Version="$(MSTestTestAdapterVersion)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageVersion Include="Microsoft.DotNet.XUnitAssert" Version="$(MicrosoftDotNetXUnitAssertVersion)" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions tests/helix/send-to-helix-inner.proj
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
<_SupportDataStagingDir>$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'support-data'))</_SupportDataStagingDir>

<PrepareDependenciesDependsOn>_StageDotNetCoverageTool;_StageCreateDotNetDevCertScripts</PrepareDependenciesDependsOn>

<!-- Disable playwright tests on helix/linux. Issue: https://github.com/dotnet/aspire/issues/4623 -->
<DisablePlaywrightTests Condition="'$(OS)' != 'Windows_NT'">true</DisablePlaywrightTests>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -40,6 +37,9 @@
<_TestNameEnvVar Condition="'$(OS)' != 'Windows_NT'">${TEST_NAME}</_TestNameEnvVar>
<_TestNameEnvVar Condition="'$(OS)' == 'Windows_NT'">%TEST_NAME%</_TestNameEnvVar>

<_TestAssemblyRootDirEnvVar Condition="'$(OS)' != 'Windows_NT'">${HELIX_WORKITEM_ROOT}</_TestAssemblyRootDirEnvVar>
<_TestAssemblyRootDirEnvVar Condition="'$(OS)' == 'Windows_NT'">%HELIX_WORKITEM_ROOT%</_TestAssemblyRootDirEnvVar>

<_CodeCoverageReportFileNameSuffixEnvVar Condition="'$(OS)' != 'Windows_NT'">${CODE_COV_FILE_SUFFIX}</_CodeCoverageReportFileNameSuffixEnvVar>
<_CodeCoverageReportFileNameSuffixEnvVar Condition="'$(OS)' == 'Windows_NT'">%CODE_COV_FILE_SUFFIX%</_CodeCoverageReportFileNameSuffixEnvVar>

Expand Down

0 comments on commit 18b92c3

Please sign in to comment.