Skip to content

Commit 18b92c3

Browse files
committed
merge from playground branch
1 parent e23cd4c commit 18b92c3

15 files changed

Lines changed: 81 additions & 27 deletions

tests/Aspire.Components.Common.Tests/Aspire.Components.Common.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<PropertyGroup>
44
<TargetFramework>$(NetCurrent)</TargetFramework>
55
<IsTestSupportProject>true</IsTestSupportProject>
6+
7+
<IncludeTestPackages Condition="'$(TestsRunningOutsideOfRepo)' == 'true'">true</IncludeTestPackages>
68
</PropertyGroup>
79

810
<ItemGroup>

tests/Aspire.EndToEnd.Tests/Aspire.EndToEnd.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<TestUsingWorkloads Condition="! ('$(ContinuousIntegrationBuild)' == 'true' and '$(OS)' == 'Windows_NT')">true</TestUsingWorkloads>
1212
<InstallWorkloadForTesting>$(TestUsingWorkloads)</InstallWorkloadForTesting>
1313

14+
<IncludeTestPackages>false</IncludeTestPackages>
1415
<SupportsRunningOutsideOfRepo>true</SupportsRunningOutsideOfRepo>
1516
<TestsRunningOutsideOfRepo Condition="'$(TestsRunningOutsideOfRepo)' == '' and '$(ContinuousIntegrationBuild)' == 'true'">true</TestsRunningOutsideOfRepo>
1617
<XunitRunnerJson>xunit.runner.json</XunitRunnerJson>

tests/Aspire.Workload.Tests/StarterTemplateRunTestsBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,3 @@ public static List<ResourceRow> GetExpectedResources(AspireProject project, bool
139139
return expectedResources;
140140
}
141141
}
142-
143-
public sealed record ResourceRow(string Type, string Name, string State, string Source, string[] Endpoints);

tests/Aspire.Workload.Tests/WorkloadTestsBase.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@ protected static async Task<ResourceRow[]> CheckDashboardHasResourcesAsync(IPage
137137

138138
AssertEqual(expectedEndpoints.Length, matchingEndpoints, $"Expected number of endpoints for {resourceName}");
139139

140-
// Check 'Source' column
141-
AssertEqual(expectedRow.Source, await cellLocs[4].InnerTextAsync(), $"Source for {resourceName}");
140+
if (expectedRow.Source is not null)
141+
{
142+
// Check 'Source' column
143+
AssertEqual(expectedRow.Source, await cellLocs[4].InnerTextAsync(), $"Source for {resourceName}");
144+
}
142145

143146
foundRows.Add(expectedRow with { Endpoints = endpointsFound.ToArray() });
144147
foundNames.Add(resourceName);

tests/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
<RunSettingsFilePath>$(RepositoryEngineeringDir)testing\.runsettings</RunSettingsFilePath>
99
<TestArchiveTestsDir Condition="'$(TestArchiveTestsDir)' == ''">$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'tests'))</TestArchiveTestsDir>
1010
<TestArchiveTestsDirForWorkloadTests Condition="'$(TestArchiveTestsDirForWorkloadTests)' == ''">$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'workload-tests'))</TestArchiveTestsDirForWorkloadTests>
11+
<TestArchiveTestsDirForPlaygroundTests Condition="'$(TestArchiveTestsDirForPlaygroundTests)' == ''">$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'playground-tests'))</TestArchiveTestsDirForPlaygroundTests>
1112
<TestArchiveTestsDirForEndToEndTests Condition="'$(TestArchiveTestsDirForEndToEndTests)' == ''">$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'e2e-tests'))</TestArchiveTestsDirForEndToEndTests>
1213
<PlaywrightDependenciesDirectory>$(ArtifactsBinDir)playwright-deps</PlaywrightDependenciesDirectory>
14+
<GeneratedPackagesVersionsPropsPath>$(IntermediateOutputPath)Directory.Packages.Versions.props</GeneratedPackagesVersionsPropsPath>
1315

1416
<!-- This is useful for local runs -->
1517
<VSTestResultsDirectory>$(ArtifactsTestResultsDir)</VSTestResultsDirectory>

tests/Directory.Build.targets

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
Overwrite="true" />
3232
</Target>
3333

34+
<!-- move to .. repo.targets?? -->
3435
<!-- generate before the build so the project can use this in a <None ..> item -->
35-
<Target Name="_GeneratePackagesVersionsProps" BeforeTargets="BeforeBuild" Condition="'$(SupportsRunningOutsideOfRepo)' == 'true' and '$(TestsRunningOutsideOfRepo)' != 'true'">
36-
<!-- FIXME: what should the condition be? Introduce a "supports tests running.. ? -->
37-
<!--Condition="'$(ArchiveTests)' == 'true' or '$(TestsRunningOutsideOfRepo)' == 'true'" -->
36+
<Target Name="_GeneratePackagesVersionsProps" BeforeTargets="BeforeBuild" Condition="'$(SupportsRunningOutsideOfRepo)' == 'true'">
3837
<!-- Duplicate all the @(PackageVersion) items with the evaluated versions -->
3938
<ItemGroup>
4039
<_PackageVersionEvaluated Include="@(PackageVersion -> '&lt;PackageVersion Include=&quot;%(Identity)&quot; Version=&quot;%(Version)&quot; /&gt;')" />

tests/Shared/Aspire.Workload.Testing.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<InstallWorkloadUsingArtifactsAfterThisTarget />
77
<TemplateNuGetConfigPath>$(RepoRoot)NuGet.config</TemplateNuGetConfigPath>
88
<PatchedNuGetConfigPath>$(ArtifactsObjDir)nuget.workload.config</PatchedNuGetConfigPath>
9-
<GeneratedPackagesVersionsPropsPath>$(ArtifactsObjDir)Directory.Packages.Versions.props</GeneratedPackagesVersionsPropsPath>
9+
<GeneratedPackagesVersionsPropsPath>$(IntermediateOutputPath)Directory.Packages.Versions.props</GeneratedPackagesVersionsPropsPath>
1010

1111
<_GlobalJsonContent>$([System.IO.File]::ReadAllText('$(RepoRoot)global.json'))</_GlobalJsonContent>
1212
<_DotNetCliVersionFromGlobalJson>$([System.Text.RegularExpressions.Regex]::Match($(_GlobalJsonContent), '(%3F&lt;="dotnet": ").*(%3F=")'))</_DotNetCliVersionFromGlobalJson>

tests/Shared/Logging/XunitLoggerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Microsoft.Extensions.Logging.Testing;
99

10-
public class XunitLoggerProvider : ILoggerProvider
10+
public sealed class XunitLoggerProvider : ILoggerProvider
1111
{
1212
private readonly ITestOutputHelper _output;
1313
private readonly LogLevel _minLevel;

tests/Shared/RepoTesting/Aspire.Testing.Repo.targets

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
when running in the repo. -->
66

77
<PropertyGroup>
8+
<SupportsRunningOutsideOfRepo Condition="'$(SupportsRunningOutsideOfRepo)' == '' and '$(IsHostingTestingProject)' == 'true'">true</SupportsRunningOutsideOfRepo>
9+
10+
<IncludeTestPackages Condition="'$(IncludeTestPackages)' == '' and ('$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true')">true</IncludeTestPackages>
811
<GeneratedPackagesVersionsPropsPath>$(IntermediateOutputPath)Directory.Packages.Versions.props</GeneratedPackagesVersionsPropsPath>
12+
<RelativeStagingDir Condition="'$(RelativeStagingDir)' == '' and '$(SupportsRunningOutsideOfRepo)' == 'true'">staging-for-archive\</RelativeStagingDir>
13+
<RelativeStagingDir>$([MSBuild]::EnsureTrailingSlash('$(RelativeStagingDir)'))</RelativeStagingDir>
14+
<TestArchiveTestsDir Condition="'$(SupportsRunningOutsideOfRepo)' == 'true'">$(TestArchiveTestsDirForPlaygroundTests)</TestArchiveTestsDir>
915
</PropertyGroup>
1016

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

33-
<ItemGroup>
39+
<ItemGroup Condition="'$(ArchiveTests)' == 'true' and '$(SupportsRunningOutsideOfRepo)' == 'true' and '$(IsTestProject)' == 'true'">
40+
<!-- needed to isolate the build -->
41+
<None Include="$(TestsSharedDir)EmptyProject.proj" Link="$(RelativeStagingDir)Directory.Build.props" CopyToOutputDirectory="PreserveNewest" />
42+
<None Include="$(TestsSharedDir)EmptyProject.proj" Link="$(RelativeStagingDir)Directory.Build.targets" CopyToOutputDirectory="PreserveNewest" />
43+
<None Include="$(TestsSharedRepoTestingDir)\*" Link="$(RelativeStagingDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
44+
45+
<None Include="$(GeneratedPackagesVersionsPropsPath)" Link="$(RelativeStagingDir)Directory.Packages.Versions.props" CopyToOutputDirectory="PreserveNewest" />
46+
47+
<None Include="$(TestsSharedDir)nuget-with-package-source-mapping.config" Link="$(RelativeStagingDir)nuget.config" CopyToOutputDirectory="PreserveNewest" />
48+
49+
<!-- FIXME: move this file to out-of-repo? -->
50+
<None Include="$(TestsSharedDir)WorkloadTesting\data\Directory.Packages.Helix.props" Link="$(RelativeStagingDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
51+
52+
<!-- FIXME: should this be in the test project?? -->
53+
<None Include="$(TestsSharedDir)\**\*" Link="staging-for-archive\tests\Shared\%(RecursiveDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
54+
</ItemGroup>
55+
56+
<ItemGroup Condition="'$(SupportsRunningOutsideOfRepo)' == 'true'">
57+
<PropertyForHelixRun Include="NetCurrent" />
3458
<PropertyForHelixRun Include="XunitVersion" />
3559
<PropertyForHelixRun Include="XunitAnalyzersVersion" />
3660
<PropertyForHelixRun Include="XunitRunnerVisualStudioVersion" />
@@ -40,9 +64,16 @@
4064
</ItemGroup>
4165

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

71+
<Target Name="_UpdateArchiveSourcePath" BeforeTargets="ZipTestArchive" Condition="'$(ArchiveTests)' == 'true'">
72+
<PropertyGroup>
73+
<TestsArchiveSourceDir>$(OutDir)$(RelativeStagingDir)</TestsArchiveSourceDir>
74+
</PropertyGroup>
75+
</Target>
76+
4677
<ImportGroup Condition="'$(RepoRoot)' != 'null' and '$(TestsRunningOutsideOfRepo)' != 'true' and '$(IsAspireHost)' == 'true'">
4778
<Import Project="$(RepoRoot)src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.targets" Condition="Exists('$(RepoRoot)src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.targets')" />
4879
<Import Project="$(RepoRoot)src\Aspire.Hosting.Sdk\SDK\Sdk.targets" Condition="Exists('$(RepoRoot)src\Aspire.Hosting.Sdk\SDK\Sdk.targets')" />

tests/Shared/WorkloadTesting/AspireProject.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static string GetNuGetConfigPathFor(string targetFramework) =>
2727
public string Id { get; init; }
2828
public string RootDir { get; init; }
2929
public string LogPath { get; init; }
30-
public string AppHostProjectDirectory => Path.Combine(RootDir, $"{Id}.AppHost");
30+
public string AppHostProjectDirectory { get; init; }
3131
public string ServiceDefaultsProjectPath => Path.Combine(RootDir, $"{Id}.ServiceDefaults");
3232
public string TestsProjectDirectory => Path.Combine(RootDir, $"{Id}.Tests");
3333
public string? DashboardUrl { get; private set; }
@@ -38,13 +38,14 @@ public static string GetNuGetConfigPathFor(string targetFramework) =>
3838
private readonly ITestOutputHelper _testOutput;
3939
private readonly BuildEnvironment _buildEnv;
4040

41-
public AspireProject(string id, string baseDir, ITestOutputHelper testOutput, BuildEnvironment buildEnv)
41+
public AspireProject(string id, string baseDir, ITestOutputHelper testOutput, BuildEnvironment buildEnv, string? relativeAppHostProjectDir = null)
4242
{
4343
Id = id;
4444
RootDir = baseDir;
4545
_testOutput = testOutput;
4646
_buildEnv = buildEnv;
4747
LogPath = Path.Combine(_buildEnv.LogRootPath, Id);
48+
AppHostProjectDirectory = relativeAppHostProjectDir ?? Path.Combine(RootDir, $"{Id}.AppHost");
4849
}
4950

5051
protected void InitPaths()
@@ -102,7 +103,11 @@ public static async Task<AspireProject> CreateNewTemplateProjectAsync(string id,
102103
return project;
103104
}
104105

105-
public async Task StartAppHostAsync(string[]? extraArgs = default, Action<ProcessStartInfo>? configureProcess = null, bool noBuild = true, CancellationToken token = default)
106+
public async Task StartAppHostAsync(string[]? extraArgs = default,
107+
Action<ProcessStartInfo>? configureProcess = null,
108+
bool noBuild = true,
109+
bool expectEndpointsHook = true,
110+
CancellationToken token = default)
106111
{
107112
if (IsRunning)
108113
{
@@ -207,7 +212,7 @@ public async Task StartAppHostAsync(string[]? extraArgs = default, Action<Proces
207212
AppHostProcess.BeginOutputReadLine();
208213
AppHostProcess.BeginErrorReadLine();
209214

210-
var successfulStartupTask = Task.WhenAll(appRunning.Task, projectsParsed.Task);
215+
var successfulStartupTask = Task.WhenAll(appRunning.Task, expectEndpointsHook ? projectsParsed.Task : Task.CompletedTask);
211216
var startupTimeoutTask = Task.Delay(TimeSpan.FromSeconds(AppStartupWaitTimeoutSecs), token);
212217

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

@@ -274,7 +279,7 @@ public async Task BuildAsync(string[]? extraBuildArgs = default, CancellationTok
274279
buildArgs += " " + string.Join(" ", extraBuildArgs);
275280
}
276281
using var buildCmd = new DotNetCommand(_testOutput, buildEnv: _buildEnv, label: "build")
277-
.WithWorkingDirectory(Path.Combine(RootDir, $"{Id}.AppHost"));
282+
.WithWorkingDirectory(AppHostProjectDirectory);
278283
res = await buildCmd.ExecuteAsync(buildArgs);
279284
res.EnsureSuccessful();
280285
}

0 commit comments

Comments
 (0)