Skip to content

Commit e90c817

Browse files
committed
Hosting test timeouts
1 parent be2a895 commit e90c817

File tree

41 files changed

+586
-595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+586
-595
lines changed

tests/Aspire.Components.Common.Tests/TestConstants.cs renamed to tests/Aspire.Components.Common.Tests/ComponentTestConstants.cs

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

44
namespace Aspire.Components.Common.Tests;
55

6-
public static class TestConstants
6+
public static class ComponentTestConstants
77
{
88
public const string AspireTestContainerRegistry = "netaspireci.azurecr.io";
99
}

tests/Aspire.Elastic.Clients.Elasticsearch.Tests/ElasticsearchContainerFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public async Task InitializeAsync()
2020
if (RequiresDockerAttribute.IsSupported)
2121
{
2222
Container = new ElasticsearchBuilder()
23-
.WithImage($"{TestConstants.AspireTestContainerRegistry}/{ElasticsearchContainerImageTags.Image}:{ElasticsearchContainerImageTags.Tag}")
23+
.WithImage($"{ComponentTestConstants.AspireTestContainerRegistry}/{ElasticsearchContainerImageTags.Image}:{ElasticsearchContainerImageTags.Tag}")
2424
.Build();
2525
await Container.StartAsync();
2626
}

tests/Aspire.Hosting.Tests/AddParameterTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Aspire.Hosting.Lifecycle;
55
using Aspire.Hosting.Publishing;
66
using Aspire.Hosting.Utils;
7+
using Microsoft.AspNetCore.InternalTesting;
78
using Microsoft.Extensions.Configuration;
89
using Microsoft.Extensions.DependencyInjection;
910
using Xunit;
@@ -147,7 +148,7 @@ public async Task ParametersWithDefaultValueStringOverloadUsedRegardlessOfConfig
147148
Assert.Equal($"DefaultValue", parameterResource.Value);
148149

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

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

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

312313
// The manifest is not affected by the custom configuration key
313-
var paramManifest = await ManifestUtils.GetManifest(appModel.Resources.OfType<ParameterResource>().Single(r => r.Name == "val"));
314+
var paramManifest = await ManifestUtils.GetManifest(appModel.Resources.OfType<ParameterResource>().Single(r => r.Name == "val")).DefaultTimeout();
314315
var expectedManifest = $$"""
315316
{
316317
"type": "parameter.v0",

tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
<Compile Include="$(TestsSharedDir)Logging\*.cs" LinkBase="shared/Logging" />
2424
<Compile Include="$(TestsSharedDir)ConsoleLogging\*.cs" LinkBase="shared" />
2525
<Compile Include="$(TestsSharedDir)AsyncTestHelpers.cs" Link="shared/AsyncTestHelpers.cs" />
26-
<Compile Include="$(TestsSharedDir)TaskExtensions.cs" Link="shared/TaskExtensions.cs" />
2726
<Compile Include="$(RepoRoot)src\Aspire.Hosting.PostgreSQL\PostgresContainerImageTags.cs" />
2827
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Redis\RedisContainerImageTags.cs" />
2928
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Testing\ResourceLoggerForwarderService.cs" Link="Utils\ResourceLoggerForwarderService.cs" />

tests/Aspire.Hosting.Tests/Dashboard/DashboardLifecycleHookTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Aspire.Hosting.Dashboard;
99
using Aspire.Hosting.Dcp;
1010
using Aspire.Hosting.Tests.Utils;
11+
using Microsoft.AspNetCore.InternalTesting;
1112
using Microsoft.Extensions.Configuration;
1213
using Microsoft.Extensions.Hosting;
1314
using Microsoft.Extensions.Logging;
@@ -42,12 +43,12 @@ public async Task WatchDashboardLogs_WrittenToHostLoggerFactory(DateTime? timest
4243
var hook = CreateHook(resourceLoggerService, resourceNotificationService, configuration, loggerFactory: factory);
4344

4445
var model = new DistributedApplicationModel(new ResourceCollection());
45-
await hook.BeforeStartAsync(model, CancellationToken.None);
46+
await hook.BeforeStartAsync(model, CancellationToken.None).DefaultTimeout();
4647

47-
await resourceNotificationService.PublishUpdateAsync(model.Resources.Single(), s => s);
48+
await resourceNotificationService.PublishUpdateAsync(model.Resources.Single(), s => s).DefaultTimeout();
4849

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

6364
// Assert
64-
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
65-
while (!cts.IsCancellationRequested)
65+
while (true)
6666
{
67-
var logContext = await logChannel.Reader.ReadAsync(cts.Token);
67+
var logContext = await logChannel.Reader.ReadAsync().DefaultTimeout();
6868
if (logContext.LoggerName == expectedCategory)
6969
{
7070
Assert.Equal(expectedMessage, logContext.Message);
@@ -86,7 +86,7 @@ public async Task BeforeStartAsync_ExcludeLifecycleCommands_CommandsNotAddedToDa
8686
var model = new DistributedApplicationModel(new ResourceCollection());
8787

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

tests/Aspire.Hosting.Tests/Dashboard/DashboardResourceTests.cs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Aspire.Hosting.Dcp;
88
using Aspire.Hosting.Tests.Utils;
99
using Aspire.Hosting.Utils;
10+
using Microsoft.AspNetCore.InternalTesting;
1011
using Microsoft.Extensions.Configuration;
1112
using Microsoft.Extensions.DependencyInjection;
1213
using Microsoft.Extensions.Logging;
@@ -40,7 +41,7 @@ public async Task DashboardIsAutomaticallyAddedAsHiddenResource()
4041

4142
using var app = builder.Build();
4243

43-
await app.ExecuteBeforeStartHooksAsync(default);
44+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
4445

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

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

6566
using var app = builder.Build();
6667

67-
await app.ExecuteBeforeStartHooksAsync(default);
68+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
6869

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

@@ -95,15 +96,15 @@ public async Task DashboardDoesNotAddResource_ConfiguresExistingDashboard()
9596

9697
using var app = builder.Build();
9798

98-
await app.ExecuteBeforeStartHooksAsync(default);
99+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
99100

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

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

104105
Assert.Same(container.Resource, dashboard);
105106

106-
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance);
107+
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance).DefaultTimeout();
107108

108109
Assert.Collection(config,
109110
e =>
@@ -165,13 +166,13 @@ public async Task DashboardWithDllPathLaunchesDotnet()
165166

166167
var app = builder.Build();
167168

168-
await app.ExecuteBeforeStartHooksAsync(default);
169+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
169170

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

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

174-
var args = await ArgumentEvaluator.GetArgumentListAsync(dashboard);
175+
var args = await ArgumentEvaluator.GetArgumentListAsync(dashboard).DefaultTimeout();
175176

176177
Assert.NotNull(dashboard);
177178
Assert.Equal("aspire-dashboard", dashboard.Name);
@@ -201,13 +202,13 @@ public async Task DashboardAuthConfigured_EnvVarsPresent()
201202

202203
using var app = builder.Build();
203204

204-
await app.ExecuteBeforeStartHooksAsync(default);
205+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
205206

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

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

210-
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance);
211+
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance).DefaultTimeout();
211212

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

237238
using var app = builder.Build();
238239

239-
await app.ExecuteBeforeStartHooksAsync(default);
240+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
240241

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

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

245-
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance);
246+
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance).DefaultTimeout();
246247

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

269270
using var app = builder.Build();
270271

271-
await app.ExecuteBeforeStartHooksAsync(default);
272+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
272273

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

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

277-
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance);
278+
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, TestServiceProvider.Instance).DefaultTimeout();
278279

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

302303
using var app = builder.Build();
303304

304-
await app.ExecuteBeforeStartHooksAsync(default);
305+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
305306

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

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

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

315-
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, app.Services);
316+
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, app.Services).DefaultTimeout();
316317

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

341342
using var app = builder.Build();
342343

343-
await app.ExecuteBeforeStartHooksAsync(default);
344+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
344345

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

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

349-
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, app.Services);
350+
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(dashboard, DistributedApplicationOperation.Run, app.Services).DefaultTimeout();
350351

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

366367
using var app = builder.Build();
367368

368-
await app.ExecuteBeforeStartHooksAsync(default);
369+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
369370

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

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

382383
var app = builder.Build();
383384

384-
await app.ExecuteBeforeStartHooksAsync(default);
385+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
385386

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

@@ -446,7 +447,7 @@ public async Task DashboardLifecycleHookWatchesLogs(LogLevel logLevel)
446447
}
447448
});
448449

449-
await app.ExecuteBeforeStartHooksAsync(default).WaitAsync(TimeSpan.FromSeconds(15));
450+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
450451

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

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

462463
// Wait for logs to be subscribed to
463-
await watchForLogSubs.WaitAsync(TimeSpan.FromSeconds(15));
464+
await watchForLogSubs.DefaultTimeout();
464465

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

483484
// Get the first log message that was logged
484-
var log = await testLogger.FirstLogTask.WaitAsync(TimeSpan.FromSeconds(15));
485+
var log = await testLogger.FirstLogTask.DefaultTimeout();
485486

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

489-
await app.DisposeAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(15));
490+
await app.DisposeAsync().AsTask().DefaultTimeout();
490491
}
491492

492493
[Fact]
@@ -498,7 +499,7 @@ public async Task DashboardIsExcludedFromManifestInPublishModeEvenIfAddedExplici
498499

499500
var app = builder.Build();
500501

501-
await app.ExecuteBeforeStartHooksAsync(default);
502+
await app.ExecuteBeforeStartHooksAsync(default).DefaultTimeout();
502503

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

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

510-
var manifest = await ManifestUtils.GetManifestOrNull(dashboard);
511+
var manifest = await ManifestUtils.GetManifestOrNull(dashboard).DefaultTimeout();
511512

512513
Assert.Equal("aspire-dashboard", dashboard.Name);
513514
Assert.Same(ManifestPublishingCallbackAnnotation.Ignore, annotation);

0 commit comments

Comments
 (0)