Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Aspire.Components.Common.Tests;

public static class TestConstants
public static class ComponentTestConstants
{
public const string AspireTestContainerRegistry = "netaspireci.azurecr.io";
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task InitializeAsync()
if (RequiresDockerAttribute.IsSupported)
{
Container = new ElasticsearchBuilder()
.WithImage($"{TestConstants.AspireTestContainerRegistry}/{ElasticsearchContainerImageTags.Image}:{ElasticsearchContainerImageTags.Tag}")
.WithImage($"{ComponentTestConstants.AspireTestContainerRegistry}/{ElasticsearchContainerImageTags.Image}:{ElasticsearchContainerImageTags.Tag}")
.Build();
await Container.StartAsync();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Aspire.Hosting.Redis.Tests/RedisFunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public async Task VerifyDatabasesAreNotDuplicatedForPersistentRedisInsightContai

var configure = (DistributedApplicationOptions options) =>
{
options.ContainerRegistryOverride = TestConstants.AspireTestContainerRegistry;
options.ContainerRegistryOverride = ComponentTestConstants.AspireTestContainerRegistry;
};

using var builder1 = TestDistributedApplicationBuilder.Create(configure, testOutputHelper);
Expand Down
9 changes: 5 additions & 4 deletions tests/Aspire.Hosting.Tests/AddParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Aspire.Hosting.Lifecycle;
using Aspire.Hosting.Publishing;
using Aspire.Hosting.Utils;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
Expand Down Expand Up @@ -147,7 +148,7 @@ public async Task ParametersWithDefaultValueStringOverloadUsedRegardlessOfConfig
Assert.Equal($"DefaultValue", parameterResource.Value);

// The manifest should not include anything about the default value
var paramManifest = await ManifestUtils.GetManifest(appModel.Resources.OfType<ParameterResource>().Single(r => r.Name == "pass"));
var paramManifest = await ManifestUtils.GetManifest(appModel.Resources.OfType<ParameterResource>().Single(r => r.Name == "pass")).DefaultTimeout();
var expectedManifest = $$"""
{
"type": "parameter.v0",
Expand Down Expand Up @@ -197,7 +198,7 @@ public async Task ParametersWithDefaultValueGetPublishedIfPublishFlagIsPassed(bo
Assert.Equal($"DefaultValue", parameterResource.Value);

// The manifest should include the default value, since we passed publishValueAsDefault: true
var paramManifest = await ManifestUtils.GetManifest(appModel.Resources.OfType<ParameterResource>().Single(r => r.Name == "pass"));
var paramManifest = await ManifestUtils.GetManifest(appModel.Resources.OfType<ParameterResource>().Single(r => r.Name == "pass")).DefaultTimeout();
var expectedManifest = $$"""
{
"type": "parameter.v0",
Expand Down Expand Up @@ -255,7 +256,7 @@ public async Task ParametersWithDefaultValueObjectOverloadUsedRegardlessOfConfig
Assert.Equal(10, parameterResource.Value.Length);

// The manifest should include the fields for the generated default value
var paramManifest = await ManifestUtils.GetManifest(appModel.Resources.OfType<ParameterResource>().Single(r => r.Name == "pass"));
var paramManifest = await ManifestUtils.GetManifest(appModel.Resources.OfType<ParameterResource>().Single(r => r.Name == "pass")).DefaultTimeout();
var expectedManifest = $$"""
{
"type": "parameter.v0",
Expand Down Expand Up @@ -310,7 +311,7 @@ public async Task ParametersCanGetValueFromNonDefaultConfigurationKeys()
Assert.Equal($"MyAccessToken", parameterResource.Value);

// The manifest is not affected by the custom configuration key
var paramManifest = await ManifestUtils.GetManifest(appModel.Resources.OfType<ParameterResource>().Single(r => r.Name == "val"));
var paramManifest = await ManifestUtils.GetManifest(appModel.Resources.OfType<ParameterResource>().Single(r => r.Name == "val")).DefaultTimeout();
var expectedManifest = $$"""
{
"type": "parameter.v0",
Expand Down
1 change: 0 additions & 1 deletion tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<Compile Include="$(TestsSharedDir)Logging\*.cs" LinkBase="shared/Logging" />
<Compile Include="$(TestsSharedDir)ConsoleLogging\*.cs" LinkBase="shared" />
<Compile Include="$(TestsSharedDir)AsyncTestHelpers.cs" Link="shared/AsyncTestHelpers.cs" />
<Compile Include="$(TestsSharedDir)TaskExtensions.cs" Link="shared/TaskExtensions.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting.PostgreSQL\PostgresContainerImageTags.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Redis\RedisContainerImageTags.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Testing\ResourceLoggerForwarderService.cs" Link="Utils\ResourceLoggerForwarderService.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Aspire.Hosting.Dashboard;
using Aspire.Hosting.Dcp;
using Aspire.Hosting.Tests.Utils;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -42,12 +43,12 @@ public async Task WatchDashboardLogs_WrittenToHostLoggerFactory(DateTime? timest
var hook = CreateHook(resourceLoggerService, resourceNotificationService, configuration, loggerFactory: factory);

var model = new DistributedApplicationModel(new ResourceCollection());
await hook.BeforeStartAsync(model, CancellationToken.None);
await hook.BeforeStartAsync(model, CancellationToken.None).DefaultTimeout();

await resourceNotificationService.PublishUpdateAsync(model.Resources.Single(), s => s);
await resourceNotificationService.PublishUpdateAsync(model.Resources.Single(), s => s).DefaultTimeout();

string resourceId = default!;
await foreach (var item in resourceLoggerService.WatchAnySubscribersAsync())
await foreach (var item in resourceLoggerService.WatchAnySubscribersAsync().DefaultTimeout())
{
if (item.Name.StartsWith(KnownResourceNames.AspireDashboard) && item.AnySubscribers)
{
Expand All @@ -61,10 +62,9 @@ public async Task WatchDashboardLogs_WrittenToHostLoggerFactory(DateTime? timest
dashboardLoggerState.AddLog(LogEntry.Create(timestamp, logMessage, isErrorMessage: false), inMemorySource: true);

// Assert
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
while (!cts.IsCancellationRequested)
while (true)
{
var logContext = await logChannel.Reader.ReadAsync(cts.Token);
var logContext = await logChannel.Reader.ReadAsync().DefaultTimeout();
if (logContext.LoggerName == expectedCategory)
{
Assert.Equal(expectedMessage, logContext.Message);
Expand All @@ -86,7 +86,7 @@ public async Task BeforeStartAsync_ExcludeLifecycleCommands_CommandsNotAddedToDa
var model = new DistributedApplicationModel(new ResourceCollection());

// Act
await hook.BeforeStartAsync(model, CancellationToken.None);
await hook.BeforeStartAsync(model, CancellationToken.None).DefaultTimeout();
var dashboardResource = model.Resources.Single(r => string.Equals(r.Name, KnownResourceNames.AspireDashboard, StringComparisons.ResourceName));
dashboardResource.AddLifeCycleCommands();

Expand Down
51 changes: 26 additions & 25 deletions tests/Aspire.Hosting.Tests/Dashboard/DashboardResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Aspire.Hosting.Dcp;
using Aspire.Hosting.Tests.Utils;
using Aspire.Hosting.Utils;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -40,7 +41,7 @@ public async Task DashboardIsAutomaticallyAddedAsHiddenResource()

using var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

Expand All @@ -64,7 +65,7 @@ public async Task DashboardIsAddedFirst()

using var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

Expand Down Expand Up @@ -95,15 +96,15 @@ public async Task DashboardDoesNotAddResource_ConfiguresExistingDashboard()

using var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

var dashboard = Assert.Single(model.Resources);

Assert.Same(container.Resource, dashboard);

var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance);
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance).DefaultTimeout();

Assert.Collection(config,
e =>
Expand Down Expand Up @@ -165,13 +166,13 @@ public async Task DashboardWithDllPathLaunchesDotnet()

var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

var dashboard = Assert.Single(model.Resources.OfType<ExecutableResource>());

var args = await ArgumentEvaluator.GetArgumentListAsync(dashboard);
var args = await ArgumentEvaluator.GetArgumentListAsync(dashboard).DefaultTimeout();

Assert.NotNull(dashboard);
Assert.Equal("aspire-dashboard", dashboard.Name);
Expand Down Expand Up @@ -201,13 +202,13 @@ public async Task DashboardAuthConfigured_EnvVarsPresent()

using var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

var dashboard = Assert.Single(model.Resources);

var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance);
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance).DefaultTimeout();

Assert.Equal("BrowserToken", config.Single(e => e.Key == DashboardConfigNames.DashboardFrontendAuthModeName.EnvVarName).Value);
Assert.Equal("TestBrowserToken!", config.Single(e => e.Key == DashboardConfigNames.DashboardFrontendBrowserTokenName.EnvVarName).Value);
Expand Down Expand Up @@ -236,13 +237,13 @@ public async Task DashboardAuthRemoved_EnvVarsUnsecured()

using var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

var dashboard = Assert.Single(model.Resources);

var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance);
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance).DefaultTimeout();

Assert.Equal("Unsecured", config.Single(e => e.Key == DashboardConfigNames.DashboardFrontendAuthModeName.EnvVarName).Value);
Assert.Equal("Unsecured", config.Single(e => e.Key == DashboardConfigNames.DashboardOtlpAuthModeName.EnvVarName).Value);
Expand All @@ -268,13 +269,13 @@ public async Task DashboardResourceServiceUriIsSet()

using var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

var dashboard = Assert.Single(model.Resources);

var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance);
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance).DefaultTimeout();

Assert.Equal("http://localhost:5000", config.Single(e => e.Key == DashboardConfigNames.ResourceServiceUrlName.EnvVarName).Value);
}
Expand All @@ -301,7 +302,7 @@ public async Task DashboardResource_OtlpHttpEndpoint_CorsEnvVarSet()

using var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

Expand All @@ -312,7 +313,7 @@ public async Task DashboardResource_OtlpHttpEndpoint_CorsEnvVarSet()

var dashboard = Assert.Single(model.Resources.Where(r => r.Name == "aspire-dashboard"));

var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, app.Services);
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, app.Services).DefaultTimeout();

Assert.Equal("http://localhost:8081,http://localhost:58080", config.Single(e => e.Key == DashboardConfigNames.DashboardOtlpCorsAllowedOriginsKeyName.EnvVarName).Value);
Assert.Equal("*", config.Single(e => e.Key == DashboardConfigNames.DashboardOtlpCorsAllowedHeadersKeyName.EnvVarName).Value);
Expand Down Expand Up @@ -340,13 +341,13 @@ public async Task DashboardResource_OtlpGrpcEndpoint_CorsEnvVarNotSet()

using var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

var dashboard = Assert.Single(model.Resources.Where(r => r.Name == "aspire-dashboard"));

var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, app.Services);
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, app.Services).DefaultTimeout();

Assert.DoesNotContain(config, e => e.Key == DashboardConfigNames.DashboardOtlpCorsAllowedOriginsKeyName.EnvVarName);
Assert.DoesNotContain(config, e => e.Key == DashboardConfigNames.DashboardOtlpCorsAllowedHeadersKeyName.EnvVarName);
Expand All @@ -365,7 +366,7 @@ public async Task DashboardIsNotAddedInPublishMode()

using var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

Expand All @@ -381,7 +382,7 @@ public async Task DashboardIsNotAddedIfDisabled()

var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

Expand Down Expand Up @@ -446,7 +447,7 @@ public async Task DashboardLifecycleHookWatchesLogs(LogLevel logLevel)
}
});

await app.ExecuteBeforeStartHooksAsync(default).WaitAsync(TimeSpan.FromSeconds(15));
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();
var resourceNotificationService = app.Services.GetRequiredService<ResourceNotificationService>();
Expand All @@ -457,10 +458,10 @@ public async Task DashboardLifecycleHookWatchesLogs(LogLevel logLevel)
Assert.Equal("aspire-dashboard", dashboard.Name);

// Push a notification through to the dashboard resource.
await resourceNotificationService.PublishUpdateAsync(dashboard, "aspire-dashboard-0", s => s with { State = "Running" });
await resourceNotificationService.PublishUpdateAsync(dashboard, "aspire-dashboard-0", s => s with { State = "Running" }).DefaultTimeout();

// Wait for logs to be subscribed to
await watchForLogSubs.WaitAsync(TimeSpan.FromSeconds(15));
await watchForLogSubs.DefaultTimeout();

// Push some logs through to the dashboard resource.
var logger = resourceLoggerService.GetLogger("aspire-dashboard-0");
Expand All @@ -481,12 +482,12 @@ public async Task DashboardLifecycleHookWatchesLogs(LogLevel logLevel)
Assert.NotNull(testLogger);

// Get the first log message that was logged
var log = await testLogger.FirstLogTask.WaitAsync(TimeSpan.FromSeconds(15));
var log = await testLogger.FirstLogTask.DefaultTimeout();

Assert.Equal("Test dashboard message", log.Message);
Assert.Equal(logLevel, log.LogLevel);

await app.DisposeAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(15));
await app.DisposeAsync().AsTask().DefaultTimeout();
}

[Fact]
Expand All @@ -498,7 +499,7 @@ public async Task DashboardIsExcludedFromManifestInPublishModeEvenIfAddedExplici

var app = builder.Build();

await app.ExecuteBeforeStartHooksAsync(default);
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

Expand All @@ -507,7 +508,7 @@ public async Task DashboardIsExcludedFromManifestInPublishModeEvenIfAddedExplici
Assert.NotNull(dashboard);
var annotation = Assert.Single(dashboard.Annotations.OfType<ManifestPublishingCallbackAnnotation>());

var manifest = await ManifestUtils.GetManifestOrNull(dashboard);
var manifest = await ManifestUtils.GetManifestOrNull(dashboard).DefaultTimeout();

Assert.Equal("aspire-dashboard", dashboard.Name);
Assert.Same(ManifestPublishingCallbackAnnotation.Ignore, annotation);
Expand Down
Loading