diff --git a/Aspire.sln b/Aspire.sln index 7972b48f7b1..e3d7b7a5795 100644 --- a/Aspire.sln +++ b/Aspire.sln @@ -643,6 +643,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecksSandbox.AppHost EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DaprServiceC", "playground\dapr\ServiceC\DaprServiceC.csproj", "{B26653B9-439E-4850-A7F8-43C6E5121952}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dashboard", "Dashboard", "{830F7CA9-8E51-4D62-832F-91F53F85B7AE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1738,7 +1740,7 @@ Global {31F5E4F3-AC4E-4538-BC7D-85BCF9CA686A} = {975F6F41-B455-451D-A312-098DE4A167B6} {A37AAFDB-545B-4599-806A-EFCB8B310446} = {975F6F41-B455-451D-A312-098DE4A167B6} {8CB12764-E469-4BB5-8554-5F9CA0F6DE18} = {975F6F41-B455-451D-A312-098DE4A167B6} - {1ABCD945-5CAA-4F30-A741-7A9DA919254A} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60} + {1ABCD945-5CAA-4F30-A741-7A9DA919254A} = {830F7CA9-8E51-4D62-832F-91F53F85B7AE} {E20280B8-8BE0-4967-AFC2-65FFCD6EC5E4} = {F534D4F8-5E3A-42FC-BCD7-4C2D6060F9C8} {6EAA089D-7ADD-4C74-B040-FD3D75DB5C75} = {C424395C-1235-41A4-BF55-07880A04368C} {9D9C360B-9DF1-4076-8416-66964427C8F3} = {C424395C-1235-41A4-BF55-07880A04368C} @@ -1820,7 +1822,7 @@ Global {157A434E-E3CA-4080-96CF-903CC3DF66E9} = {8AA07A14-A4A7-45EC-B0F6-4690B516B16D} {921CB408-5E37-4354-B4CF-EAE517F633DC} = {8AA07A14-A4A7-45EC-B0F6-4690B516B16D} {C774BE00-EE93-4148-B866-8F0F2BA1E473} = {C424395C-1235-41A4-BF55-07880A04368C} - {0870A667-FB0C-4758-AEAF-9E5F092AD7C1} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60} + {0870A667-FB0C-4758-AEAF-9E5F092AD7C1} = {830F7CA9-8E51-4D62-832F-91F53F85B7AE} {C4833DEC-0A4F-4504-B8D0-06C60B84119C} = {91F22EEA-EB23-425A-9B32-9438A0809F4B} {9CA94707-E801-444F-A582-D5BD0104CF9B} = {91F22EEA-EB23-425A-9B32-9438A0809F4B} {3216CF59-84B0-46FF-8572-D0AFB0155423} = {A7C6452C-FEDB-4883-9AE7-29892D260AA3} @@ -1998,6 +2000,7 @@ Global {B7345F72-712F-436C-AE18-CAF7CDD4A990} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0} {042DD8C6-A26C-4B06-80A1-FE7F8659C5BC} = {B7345F72-712F-436C-AE18-CAF7CDD4A990} {B26653B9-439E-4850-A7F8-43C6E5121952} = {57A42144-739E-49A7-BADB-BB8F5F20FA17} + {830F7CA9-8E51-4D62-832F-91F53F85B7AE} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C} diff --git a/tests/Aspire.Dashboard.Tests/BrowserSecurityHeadersMiddlewareTests.cs b/tests/Aspire.Dashboard.Tests/BrowserSecurityHeadersMiddlewareTests.cs index 366b014e82c..99166c1a669 100644 --- a/tests/Aspire.Dashboard.Tests/BrowserSecurityHeadersMiddlewareTests.cs +++ b/tests/Aspire.Dashboard.Tests/BrowserSecurityHeadersMiddlewareTests.cs @@ -4,6 +4,7 @@ using Aspire.Dashboard.Authentication.Connection; using Aspire.Dashboard.Model; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Primitives; @@ -21,7 +22,7 @@ public async Task InvokeAsync_Development_AllowExternalFetch() var httpContext = new DefaultHttpContext(); // Act - await middleware.InvokeAsync(httpContext); + await middleware.InvokeAsync(httpContext).DefaultTimeout(); // Assert Assert.NotEqual(StringValues.Empty, httpContext.Response.Headers.ContentSecurityPolicy); @@ -36,7 +37,7 @@ public async Task InvokeAsync_Production_DenyExternalFetch() var httpContext = new DefaultHttpContext(); // Act - await middleware.InvokeAsync(httpContext); + await middleware.InvokeAsync(httpContext).DefaultTimeout(); // Assert Assert.NotEqual(StringValues.Empty, httpContext.Response.Headers.ContentSecurityPolicy); @@ -54,7 +55,7 @@ public async Task InvokeAsync_Scheme_ImageSourceChangesOnScheme(string scheme, s httpContext.Request.Scheme = scheme; // Act - await middleware.InvokeAsync(httpContext); + await middleware.InvokeAsync(httpContext).DefaultTimeout(); // Assert Assert.NotEqual(StringValues.Empty, httpContext.Response.Headers.ContentSecurityPolicy); @@ -70,7 +71,7 @@ public async Task InvokeAsync_Otlp_NotAdded() httpContext.Features.Set(new TestConnectionTypeFeature { ConnectionTypes = [ConnectionType.Otlp] }); // Act - await middleware.InvokeAsync(httpContext); + await middleware.InvokeAsync(httpContext).DefaultTimeout(); // Assert Assert.Equal(StringValues.Empty, httpContext.Response.Headers.ContentSecurityPolicy); diff --git a/tests/Aspire.Dashboard.Tests/ChannelExtensionsTests.cs b/tests/Aspire.Dashboard.Tests/ChannelExtensionsTests.cs index 8f73c37fc4d..30f5353222a 100644 --- a/tests/Aspire.Dashboard.Tests/ChannelExtensionsTests.cs +++ b/tests/Aspire.Dashboard.Tests/ChannelExtensionsTests.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Threading.Channels; using Aspire.Dashboard.Utils; +using Microsoft.AspNetCore.InternalTesting; using Xunit; namespace Aspire.Dashboard.Tests; @@ -31,7 +32,7 @@ public async Task GetBatchesAsync_CancellationToken_Exits() }); // Assert - await TaskHelpers.WaitIgnoreCancelAsync(readTask); + await TaskHelpers.WaitIgnoreCancelAsync(readTask).DefaultTimeout(); } [Fact] @@ -55,7 +56,7 @@ public async Task GetBatchesAsync_WithCancellation_Exits() }); // Assert - await TaskHelpers.WaitIgnoreCancelAsync(readTask); + await TaskHelpers.WaitIgnoreCancelAsync(readTask).DefaultTimeout(); } [Fact] @@ -87,19 +88,19 @@ public async Task GetBatchesAsync_MinReadInterval_WaitForNextRead() // Assert var stopwatch = Stopwatch.StartNew(); - var read1 = await resultChannel.Reader.ReadAsync(); + var read1 = await resultChannel.Reader.ReadAsync().DefaultTimeout(); Assert.Equal(["a", "b", "c"], read1.Single()); channel.Writer.TryWrite(["d", "e", "f"]); - var read2 = await resultChannel.Reader.ReadAsync(); + var read2 = await resultChannel.Reader.ReadAsync().DefaultTimeout(); Assert.Equal(["d", "e", "f"], read2.Single()); var elapsed = stopwatch.Elapsed; CustomAssert.AssertExceedsMinInterval(elapsed, minReadInterval); channel.Writer.Complete(); - await TaskHelpers.WaitIgnoreCancelAsync(readTask); + await TaskHelpers.WaitIgnoreCancelAsync(readTask).DefaultTimeout(); } [Fact] @@ -131,18 +132,18 @@ public async Task GetBatchesAsync_MinReadInterval_WithCancellation_Exit() // Assert var stopwatch = Stopwatch.StartNew(); - var read1 = await resultChannel.Reader.ReadAsync(); + var read1 = await resultChannel.Reader.ReadAsync().DefaultTimeout(); Assert.Equal(["a", "b", "c"], read1.Single()); channel.Writer.TryWrite(["d", "e", "f"]); - var read2Task = resultChannel.Reader.ReadAsync(); + var read2Task = resultChannel.Reader.ReadAsync().DefaultTimeout(); cts.Cancel(); - await TaskHelpers.WaitIgnoreCancelAsync(readTask); + await TaskHelpers.WaitIgnoreCancelAsync(readTask).DefaultTimeout(); try { - await read2Task; + await read2Task.DefaultTimeout(); } catch (ChannelClosedException) { diff --git a/tests/Aspire.Dashboard.Tests/Integration/DashboardClientAuthTests.cs b/tests/Aspire.Dashboard.Tests/Integration/DashboardClientAuthTests.cs index 73a841cd15e..18737f14703 100644 --- a/tests/Aspire.Dashboard.Tests/Integration/DashboardClientAuthTests.cs +++ b/tests/Aspire.Dashboard.Tests/Integration/DashboardClientAuthTests.cs @@ -11,6 +11,7 @@ using Grpc.Core; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -40,10 +41,10 @@ public DashboardClientAuthTests(ITestOutputHelper testOutputHelper) public async Task ConnectsToResourceService_Unsecured(bool useHttps) { var loggerFactory = IntegrationTestHelpers.CreateLoggerFactory(_testOutputHelper); - await using var server = await CreateResourceServiceServerAsync(loggerFactory, useHttps); - await using var client = await CreateDashboardClientAsync(loggerFactory, server.Url, authMode: ResourceClientAuthMode.Unsecured); + await using var server = await CreateResourceServiceServerAsync(loggerFactory, useHttps).DefaultTimeout(); + await using var client = await CreateDashboardClientAsync(loggerFactory, server.Url, authMode: ResourceClientAuthMode.Unsecured).DefaultTimeout(); - var call = await server.Calls.ApplicationInformationCallsChannel.Reader.ReadAsync(); + var call = await server.Calls.ApplicationInformationCallsChannel.Reader.ReadAsync().DefaultTimeout(); Assert.NotNull(call.Request); Assert.NotNull(call.RequestHeaders); @@ -56,10 +57,10 @@ public async Task ConnectsToResourceService_Unsecured(bool useHttps) public async Task ConnectsToResourceService_ApiKey(bool useHttps) { var loggerFactory = IntegrationTestHelpers.CreateLoggerFactory(_testOutputHelper); - await using var server = await CreateResourceServiceServerAsync(loggerFactory, useHttps); - await using var client = await CreateDashboardClientAsync(loggerFactory, server.Url, authMode: ResourceClientAuthMode.ApiKey, configureOptions: options => options.ResourceServiceClient.ApiKey = "TestApiKey!"); + await using var server = await CreateResourceServiceServerAsync(loggerFactory, useHttps).DefaultTimeout(); + await using var client = await CreateDashboardClientAsync(loggerFactory, server.Url, authMode: ResourceClientAuthMode.ApiKey, configureOptions: options => options.ResourceServiceClient.ApiKey = "TestApiKey!").DefaultTimeout(); - var call = await server.Calls.ApplicationInformationCallsChannel.Reader.ReadAsync(); + var call = await server.Calls.ApplicationInformationCallsChannel.Reader.ReadAsync().DefaultTimeout(); Assert.NotNull(call.Request); Assert.NotNull(call.RequestHeaders); diff --git a/tests/Aspire.Dashboard.Tests/Integration/FrontendBrowserTokenAuthTests.cs b/tests/Aspire.Dashboard.Tests/Integration/FrontendBrowserTokenAuthTests.cs index b3dba26b6c7..a296f82fd2e 100644 --- a/tests/Aspire.Dashboard.Tests/Integration/FrontendBrowserTokenAuthTests.cs +++ b/tests/Aspire.Dashboard.Tests/Integration/FrontendBrowserTokenAuthTests.cs @@ -8,6 +8,7 @@ using Aspire.Dashboard.Configuration; using Aspire.Dashboard.Utils; using Aspire.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; using Xunit; @@ -34,12 +35,12 @@ public async Task Get_Unauthenticated_RedirectToLogin() config[DashboardConfigNames.DashboardFrontendAuthModeName.ConfigKey] = FrontendAuthMode.BrowserToken.ToString(); config[DashboardConfigNames.DashboardFrontendBrowserTokenName.ConfigKey] = apiKey; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var client = new HttpClient { BaseAddress = new Uri($"http://{app.FrontendSingleEndPointAccessor().EndPoint}") }; // Act - var response = await client.GetAsync("/"); + var response = await client.GetAsync("/").DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -56,19 +57,19 @@ public async Task Get_LoginPage_ValidToken_RedirectToApp() config[DashboardConfigNames.DashboardFrontendAuthModeName.ConfigKey] = FrontendAuthMode.BrowserToken.ToString(); config[DashboardConfigNames.DashboardFrontendBrowserTokenName.ConfigKey] = apiKey; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var client = new HttpClient { BaseAddress = new Uri($"http://{app.FrontendSingleEndPointAccessor().EndPoint}") }; // Act 1 - var response1 = await client.GetAsync(DashboardUrls.LoginUrl(returnUrl: DashboardUrls.TracesUrl(), token: apiKey)); + var response1 = await client.GetAsync(DashboardUrls.LoginUrl(returnUrl: DashboardUrls.TracesUrl(), token: apiKey)).DefaultTimeout(); // Assert 1 Assert.Equal(HttpStatusCode.OK, response1.StatusCode); Assert.Equal(DashboardUrls.TracesUrl(), response1.RequestMessage!.RequestUri!.PathAndQuery); // Act 2 - var response2 = await client.GetAsync(DashboardUrls.StructuredLogsUrl()); + var response2 = await client.GetAsync(DashboardUrls.StructuredLogsUrl()).DefaultTimeout(); // Assert 2 Assert.Equal(HttpStatusCode.OK, response2.StatusCode); @@ -87,12 +88,12 @@ public async Task Get_LoginPage_ValidToken_OtlpHttpConnection_Denied() config[DashboardConfigNames.DashboardFrontendAuthModeName.ConfigKey] = FrontendAuthMode.BrowserToken.ToString(); config[DashboardConfigNames.DashboardFrontendBrowserTokenName.ConfigKey] = apiKey; }, testSink: testSink); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var client = new HttpClient { BaseAddress = new Uri($"http://{app.OtlpServiceHttpEndPointAccessor().EndPoint}") }; // Act - var response = await client.GetAsync(DashboardUrls.LoginUrl(returnUrl: DashboardUrls.TracesUrl(), token: apiKey)); + var response = await client.GetAsync(DashboardUrls.LoginUrl(returnUrl: DashboardUrls.TracesUrl(), token: apiKey)).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); @@ -111,12 +112,12 @@ public async Task Get_LoginPage_InvalidToken_RedirectToLoginWithoutToken() config[DashboardConfigNames.DashboardFrontendAuthModeName.ConfigKey] = FrontendAuthMode.BrowserToken.ToString(); config[DashboardConfigNames.DashboardFrontendBrowserTokenName.ConfigKey] = apiKey; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var client = new HttpClient { BaseAddress = new Uri($"http://{app.FrontendSingleEndPointAccessor().EndPoint}") }; // Act - var response = await client.GetAsync(DashboardUrls.LoginUrl(returnUrl: DashboardUrls.TracesUrl(), token: "Wrong!")); + var response = await client.GetAsync(DashboardUrls.LoginUrl(returnUrl: DashboardUrls.TracesUrl(), token: "Wrong!")).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -136,12 +137,12 @@ public async Task Post_ValidateTokenApi_AvailableBasedOnOptions(FrontendAuthMode config[DashboardConfigNames.DashboardFrontendAuthModeName.ConfigKey] = authMode.ToString(); config[DashboardConfigNames.DashboardFrontendBrowserTokenName.ConfigKey] = apiKey; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var client = new HttpClient { BaseAddress = new Uri($"http://{app.FrontendSingleEndPointAccessor().EndPoint}") }; // Act - var response = await client.PostAsync("/api/validatetoken?token=" + requestToken, content: null); + var response = await client.PostAsync("/api/validatetoken?token=" + requestToken, content: null).DefaultTimeout(); // Assert Assert.Equal(statusCode, response.StatusCode); @@ -164,7 +165,7 @@ public async Task LogOutput_NoToken_GeneratedTokenLogged() }, testSink: testSink); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); // Assert var l = testSink.Writes.Where(w => w.LoggerName == typeof(DashboardWebApplication).FullName).ToList(); @@ -225,7 +226,7 @@ public async Task LogOutput_AnyIP_LoginLinkLocalhost(string frontendUrl, string }, testSink: testSink); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); // Assert var l = testSink.Writes.Where(w => w.LoggerName == typeof(DashboardWebApplication).FullName).ToList(); @@ -252,7 +253,7 @@ public async Task LogOutput_InContainer_LoginLinkContainerMessage() }, testSink: testSink); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); // Assert var l = testSink.Writes.Where(w => w.LoggerName == typeof(DashboardWebApplication).FullName).ToList(); diff --git a/tests/Aspire.Dashboard.Tests/Integration/FrontendOpenIdConnectAuthTests.cs b/tests/Aspire.Dashboard.Tests/Integration/FrontendOpenIdConnectAuthTests.cs index bd2d429e344..ea69717bade 100644 --- a/tests/Aspire.Dashboard.Tests/Integration/FrontendOpenIdConnectAuthTests.cs +++ b/tests/Aspire.Dashboard.Tests/Integration/FrontendOpenIdConnectAuthTests.cs @@ -5,6 +5,7 @@ using System.Web; using Aspire.Dashboard.Authentication; using Aspire.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.Extensions.Logging.Testing; using Xunit; using Xunit.Abstractions; @@ -16,7 +17,7 @@ public class FrontendOpenIdConnectAuthTests(ITestOutputHelper testOutputHelper) [Fact] public async Task Get_Unauthenticated_RedirectsToAuthority() { - await using var authority = await MockOpenIdAuthority.CreateAsync(); + await using var authority = await MockOpenIdAuthority.CreateAsync().DefaultTimeout(); await using var app = IntegrationTestHelpers.CreateDashboardWebApplication( testOutputHelper, @@ -25,7 +26,7 @@ public async Task Get_Unauthenticated_RedirectsToAuthority() ConfigureOpenIdConnect(config, authority); }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); var handler = new HttpClientHandler() { @@ -36,7 +37,7 @@ public async Task Get_Unauthenticated_RedirectsToAuthority() using var client = new HttpClient(handler) { BaseAddress = new Uri($"http://{app.FrontendSingleEndPointAccessor().EndPoint}") }; // Act - var response = await client.GetAsync("/"); + var response = await client.GetAsync("/").DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.Redirect, response.StatusCode); @@ -53,13 +54,13 @@ public async Task Get_Unauthenticated_RedirectsToAuthority() Assert.Equal("code", query.Get("response_type")); Assert.Equal("openid profile", query.Get("scope")); - await app.StopAsync(); + await app.StopAsync().DefaultTimeout(); } [Fact] public async Task Get_Unauthenticated_OtlpHttpConnection_Denied() { - await using var authority = await MockOpenIdAuthority.CreateAsync(); + await using var authority = await MockOpenIdAuthority.CreateAsync().DefaultTimeout(); var testSink = new TestSink(); await using var app = IntegrationTestHelpers.CreateDashboardWebApplication( @@ -70,7 +71,7 @@ public async Task Get_Unauthenticated_OtlpHttpConnection_Denied() }, testSink: testSink); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); var handler = new HttpClientHandler() { @@ -81,7 +82,7 @@ public async Task Get_Unauthenticated_OtlpHttpConnection_Denied() using var client = new HttpClient(handler) { BaseAddress = new Uri($"http://{app.OtlpServiceHttpEndPointAccessor().EndPoint}") }; // Act - var response = await client.GetAsync("/"); + var response = await client.GetAsync("/").DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); @@ -89,7 +90,7 @@ public async Task Get_Unauthenticated_OtlpHttpConnection_Denied() var log = testSink.Writes.Single(s => s.LoggerName == typeof(FrontendCompositeAuthenticationHandler).FullName && s.EventId.Name == "AuthenticationSchemeNotAuthenticatedWithFailure"); Assert.Equal("FrontendComposite was not authenticated. Failure message: Connection type Frontend is not enabled on this connection.", log.Message); - await app.StopAsync(); + await app.StopAsync().DefaultTimeout(); } private static void ConfigureOpenIdConnect(Dictionary config, MockOpenIdAuthority.Authority authority) diff --git a/tests/Aspire.Dashboard.Tests/Integration/OtlpCorsHttpServiceTests.cs b/tests/Aspire.Dashboard.Tests/Integration/OtlpCorsHttpServiceTests.cs index 8f099eedf0b..a83369eaccc 100644 --- a/tests/Aspire.Dashboard.Tests/Integration/OtlpCorsHttpServiceTests.cs +++ b/tests/Aspire.Dashboard.Tests/Integration/OtlpCorsHttpServiceTests.cs @@ -3,6 +3,7 @@ using System.Net; using Aspire.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Xunit; using Xunit.Abstractions; @@ -22,7 +23,7 @@ public async Task ReceivePreflight_OtlpHttpEndPoint_NoCorsConfiguration_NotFound { // Arrange await using var app = IntegrationTestHelpers.CreateDashboardWebApplication(_testOutputHelper); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClient = IntegrationTestHelpers.CreateHttpClient($"http://{app.OtlpServiceHttpEndPointAccessor().EndPoint}"); @@ -32,7 +33,7 @@ public async Task ReceivePreflight_OtlpHttpEndPoint_NoCorsConfiguration_NotFound preflightRequest.Headers.TryAddWithoutValidation("Origin", "http://localhost:8000"); // Act - var responseMessage = await httpClient.SendAsync(preflightRequest); + var responseMessage = await httpClient.SendAsync(preflightRequest).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.NotFound, responseMessage.StatusCode); @@ -46,7 +47,7 @@ public async Task ReceivePreflight_OtlpHttpEndPoint_ValidCorsOrigin_Success() { config[DashboardConfigNames.DashboardOtlpCorsAllowedOriginsKeyName.ConfigKey] = "http://localhost:8000, http://localhost:8001"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClient = IntegrationTestHelpers.CreateHttpClient($"http://{app.OtlpServiceHttpEndPointAccessor().EndPoint}"); @@ -56,7 +57,7 @@ public async Task ReceivePreflight_OtlpHttpEndPoint_ValidCorsOrigin_Success() preflightRequest1.Headers.TryAddWithoutValidation("Access-Control-Request-Headers", "x-requested-with,x-custom,Content-Type"); preflightRequest1.Headers.TryAddWithoutValidation("Origin", "http://localhost:8000"); - var responseMessage1 = await httpClient.SendAsync(preflightRequest1); + var responseMessage1 = await httpClient.SendAsync(preflightRequest1).DefaultTimeout(); // Assert 1 Assert.Equal(HttpStatusCode.NoContent, responseMessage1.StatusCode); @@ -70,7 +71,7 @@ public async Task ReceivePreflight_OtlpHttpEndPoint_ValidCorsOrigin_Success() preflightRequest2.Headers.TryAddWithoutValidation("Access-Control-Request-Headers", "x-requested-with,x-custom,Content-Type"); preflightRequest2.Headers.TryAddWithoutValidation("Origin", "http://localhost:8001"); - var responseMessage2 = await httpClient.SendAsync(preflightRequest2); + var responseMessage2 = await httpClient.SendAsync(preflightRequest2).DefaultTimeout(); // Assert 2 Assert.Equal(HttpStatusCode.NoContent, responseMessage2.StatusCode); @@ -87,7 +88,7 @@ public async Task ReceivePreflight_OtlpHttpEndPoint_InvalidCorsOrigin_NoCorsHead { config[DashboardConfigNames.DashboardOtlpCorsAllowedOriginsKeyName.ConfigKey] = "http://localhost:8000"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClient = IntegrationTestHelpers.CreateHttpClient($"http://{app.OtlpServiceHttpEndPointAccessor().EndPoint}"); @@ -97,7 +98,7 @@ public async Task ReceivePreflight_OtlpHttpEndPoint_InvalidCorsOrigin_NoCorsHead preflightRequest.Headers.TryAddWithoutValidation("Origin", "http://localhost:8001"); // Act - var responseMessage = await httpClient.SendAsync(preflightRequest); + var responseMessage = await httpClient.SendAsync(preflightRequest).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.NoContent, responseMessage.StatusCode); @@ -115,7 +116,7 @@ public async Task ReceivePreflight_OtlpHttpEndPoint_AnyOrigin_Success() config[DashboardConfigNames.DashboardOtlpCorsAllowedOriginsKeyName.ConfigKey] = "*"; config[DashboardConfigNames.DashboardOtlpCorsAllowedHeadersKeyName.ConfigKey] = "*"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClient = IntegrationTestHelpers.CreateHttpClient($"http://{app.OtlpServiceHttpEndPointAccessor().EndPoint}"); @@ -125,7 +126,7 @@ public async Task ReceivePreflight_OtlpHttpEndPoint_AnyOrigin_Success() preflightRequest.Headers.TryAddWithoutValidation("Origin", "http://localhost:8000"); // Act - var responseMessage = await httpClient.SendAsync(preflightRequest); + var responseMessage = await httpClient.SendAsync(preflightRequest).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.NoContent, responseMessage.StatusCode); diff --git a/tests/Aspire.Dashboard.Tests/Integration/OtlpGrpcServiceTests.cs b/tests/Aspire.Dashboard.Tests/Integration/OtlpGrpcServiceTests.cs index 1649dd3d243..ba68491475d 100644 --- a/tests/Aspire.Dashboard.Tests/Integration/OtlpGrpcServiceTests.cs +++ b/tests/Aspire.Dashboard.Tests/Integration/OtlpGrpcServiceTests.cs @@ -30,15 +30,15 @@ public async Task CallService_OtlpGrpcEndPoint_Success() { // Arrange await using var app = IntegrationTestHelpers.CreateDashboardWebApplication(_testOutputHelper); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var channel = IntegrationTestHelpers.CreateGrpcChannel($"http://{app.OtlpServiceGrpcEndPointAccessor().EndPoint}", _testOutputHelper); var client = new LogsService.LogsServiceClient(channel); // Act var response = client.ExportAsync(new ExportLogsServiceRequest()); - var message = await response.ResponseAsync; - var headers = await response.ResponseHeadersAsync; + var message = await response.ResponseAsync.DefaultTimeout(); + var headers = await response.ResponseHeadersAsync.DefaultTimeout(); // Assert Assert.Null(headers.GetValue("content-security-policy")); @@ -55,13 +55,13 @@ public async Task CallService_OtlpGrpcEndPoint_RequiredApiKeyMissing_Failure() config[DashboardConfigNames.DashboardOtlpAuthModeName.ConfigKey] = OtlpAuthMode.ApiKey.ToString(); config[DashboardConfigNames.DashboardOtlpPrimaryApiKeyName.ConfigKey] = apiKey; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var channel = IntegrationTestHelpers.CreateGrpcChannel($"http://{app.OtlpServiceGrpcEndPointAccessor().EndPoint}", _testOutputHelper); var client = new LogsService.LogsServiceClient(channel); // Act - var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync); + var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync).DefaultTimeout(); // Assert Assert.Equal(StatusCode.Unauthenticated, ex.StatusCode); @@ -77,7 +77,7 @@ public async Task CallService_OtlpGrpcEndPoint_RequiredApiKeyWrong_Failure() config[DashboardConfigNames.DashboardOtlpAuthModeName.ConfigKey] = OtlpAuthMode.ApiKey.ToString(); config[DashboardConfigNames.DashboardOtlpPrimaryApiKeyName.ConfigKey] = apiKey; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var channel = IntegrationTestHelpers.CreateGrpcChannel($"http://{app.OtlpServiceGrpcEndPointAccessor().EndPoint}", _testOutputHelper); var client = new LogsService.LogsServiceClient(channel); @@ -88,7 +88,7 @@ public async Task CallService_OtlpGrpcEndPoint_RequiredApiKeyWrong_Failure() }; // Act - var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest(), metadata).ResponseAsync); + var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest(), metadata).ResponseAsync).DefaultTimeout(); // Assert Assert.Equal(StatusCode.Unauthenticated, ex.StatusCode); @@ -104,7 +104,7 @@ public async Task CallService_OtlpGrpcEndPoint_RequiredApiKeySent_Success() config[DashboardConfigNames.DashboardOtlpAuthModeName.ConfigKey] = OtlpAuthMode.ApiKey.ToString(); config[DashboardConfigNames.DashboardOtlpPrimaryApiKeyName.ConfigKey] = apiKey; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var channel = IntegrationTestHelpers.CreateGrpcChannel($"http://{app.OtlpServiceGrpcEndPointAccessor().EndPoint}", _testOutputHelper); var client = new LogsService.LogsServiceClient(channel); @@ -115,7 +115,7 @@ public async Task CallService_OtlpGrpcEndPoint_RequiredApiKeySent_Success() }; // Act - var response = await client.ExportAsync(new ExportLogsServiceRequest(), metadata); + var response = await client.ExportAsync(new ExportLogsServiceRequest(), metadata).ResponseAsync.DefaultTimeout(); // Assert Assert.Equal(0, response.PartialSuccess.RejectedLogRecords); @@ -133,7 +133,7 @@ public async Task CallService_OtlpGrpcEndPoint_RequiredSecondaryApiKeySent_Succe config[DashboardConfigNames.DashboardOtlpPrimaryApiKeyName.ConfigKey] = apiKey; config[DashboardConfigNames.DashboardOtlpSecondaryApiKeyName.ConfigKey] = secondaryApiKey; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var channel = IntegrationTestHelpers.CreateGrpcChannel($"http://{app.OtlpServiceGrpcEndPointAccessor().EndPoint}", _testOutputHelper); var client = new LogsService.LogsServiceClient(channel); @@ -144,7 +144,7 @@ public async Task CallService_OtlpGrpcEndPoint_RequiredSecondaryApiKeySent_Succe }; // Act - var response = await client.ExportAsync(new ExportLogsServiceRequest(), metadata); + var response = await client.ExportAsync(new ExportLogsServiceRequest(), metadata).ResponseAsync.DefaultTimeout(); // Assert Assert.Equal(0, response.PartialSuccess.RejectedLogRecords); @@ -172,13 +172,13 @@ public async Task CallService_OtlpGrpcEndPoint_ExternalFile_FileChanged_UseConfi } }; logger.LogInformation("Writing original JSON file."); - await File.WriteAllTextAsync(configPath, configJson.ToString()); + await File.WriteAllTextAsync(configPath, configJson.ToString()).DefaultTimeout(); await using var app = IntegrationTestHelpers.CreateDashboardWebApplication(loggerFactory, config => { config[DashboardConfigNames.DashboardConfigFilePathName.ConfigKey] = configPath; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var channel = IntegrationTestHelpers.CreateGrpcChannel($"http://{app.OtlpServiceGrpcEndPointAccessor().EndPoint}", loggerFactory); var client = new LogsService.LogsServiceClient(channel); @@ -189,7 +189,7 @@ public async Task CallService_OtlpGrpcEndPoint_ExternalFile_FileChanged_UseConfi }; // Act 1 - var response1 = await client.ExportAsync(new ExportLogsServiceRequest(), metadata); + var response1 = await client.ExportAsync(new ExportLogsServiceRequest(), metadata).ResponseAsync.DefaultTimeout(); // Assert 1 Assert.Equal(0, response1.PartialSuccess.RejectedLogRecords); @@ -215,7 +215,7 @@ public async Task CallService_OtlpGrpcEndPoint_ExternalFile_FileChanged_UseConfi }; logger.LogInformation("Writing new JSON file."); - await File.WriteAllTextAsync(configPath, configJson.ToString()); + await File.WriteAllTextAsync(configPath, configJson.ToString()).DefaultTimeout(); logger.LogInformation("Waiting for options change."); var options = await tcs.Task; @@ -225,7 +225,7 @@ public async Task CallService_OtlpGrpcEndPoint_ExternalFile_FileChanged_UseConfi // Act 2 logger.LogInformation("Client sends new request with old API key."); - var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest(), metadata).ResponseAsync); + var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest(), metadata).ResponseAsync).DefaultTimeout(); // Assert 2 Assert.Equal(StatusCode.Unauthenticated, ex.StatusCode); @@ -242,7 +242,7 @@ public async Task CallService_BrowserEndPoint_Failure() // Change dashboard to HTTPS so the caller can negotiate a HTTP/2 connection. config[DashboardConfigNames.DashboardFrontendUrlName.ConfigKey] = "https://127.0.0.1:0"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var channel = IntegrationTestHelpers.CreateGrpcChannel( $"https://{app.FrontendSingleEndPointAccessor().EndPoint}", @@ -254,7 +254,7 @@ public async Task CallService_BrowserEndPoint_Failure() var client = new LogsService.LogsServiceClient(channel); // Act - var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync); + var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync).DefaultTimeout(); // Assert Assert.Equal(StatusCode.Unauthenticated, ex.StatusCode); @@ -273,13 +273,13 @@ public async Task CallService_OtlpEndpoint_RequiredClientCertificateMissing_Fail config[DashboardConfigNames.DashboardOtlpAuthModeName.ConfigKey] = OtlpAuthMode.ClientCertificate.ToString(); }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var channel = IntegrationTestHelpers.CreateGrpcChannel($"https://{app.OtlpServiceGrpcEndPointAccessor().EndPoint}", _testOutputHelper); var client = new LogsService.LogsServiceClient(channel); // Act - var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync); + var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync).DefaultTimeout(); // Assert // StatusCode can change depending upon order of execution inside HttpClient. @@ -307,7 +307,7 @@ public async Task CallService_OtlpEndpoint_RequiredClientCertificateValid_Succes config["Dashboard:Otlp:CertificateAuthOptions:AllowedCertificateTypes"] = "SelfSigned"; config["Dashboard:Otlp:CertificateAuthOptions:ValidateValidityPeriod"] = "false"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); var clientCertificate = TestCertificateLoader.GetTestCertificate("eku.client.pfx"); using var channel = IntegrationTestHelpers.CreateGrpcChannel( @@ -318,7 +318,7 @@ public async Task CallService_OtlpEndpoint_RequiredClientCertificateValid_Succes var client = new LogsService.LogsServiceClient(channel); // Act - var response = await client.ExportAsync(new ExportLogsServiceRequest()); + var response = await client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync.DefaultTimeout(); // Assert Assert.Equal(0, response.PartialSuccess.RejectedLogRecords); @@ -344,7 +344,7 @@ public async Task CallService_OtlpEndpoint_RequiredClientCertificateSHA1Thumbpri config["Dashboard:Otlp:CertificateAuthOptions:AllowedCertificateTypes"] = "SelfSigned"; config["Dashboard:Otlp:CertificateAuthOptions:ValidateValidityPeriod"] = "false"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var channel = IntegrationTestHelpers.CreateGrpcChannel( $"https://{app.OtlpServiceGrpcEndPointAccessor().EndPoint}", @@ -358,7 +358,7 @@ public async Task CallService_OtlpEndpoint_RequiredClientCertificateSHA1Thumbpri var client = new LogsService.LogsServiceClient(channel); // Act - var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync); + var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync).DefaultTimeout(); // Assert Assert.Equal(StatusCode.Unauthenticated, ex.StatusCode); @@ -382,7 +382,7 @@ public async Task CallService_OtlpEndpoint_RequiredClientCertificateValid_NotInA config["Authentication:Schemes:Certificate:AllowedCertificateTypes"] = "SelfSigned"; config["Authentication:Schemes:Certificate:ValidateValidityPeriod"] = "false"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); var clientCertificates = new X509CertificateCollection(new[] { TestCertificateLoader.GetTestCertificate("eku.client.pfx") }); using var channel = IntegrationTestHelpers.CreateGrpcChannel( @@ -397,7 +397,7 @@ public async Task CallService_OtlpEndpoint_RequiredClientCertificateValid_NotInA var client = new LogsService.LogsServiceClient(channel); // Act - var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync); + var ex = await Assert.ThrowsAsync(() => client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync).DefaultTimeout(); // Assert Assert.Equal(StatusCode.Unauthenticated, ex.StatusCode); diff --git a/tests/Aspire.Dashboard.Tests/Integration/OtlpHttpServiceTests.cs b/tests/Aspire.Dashboard.Tests/Integration/OtlpHttpServiceTests.cs index 1933ff87573..9aea2ad1e76 100644 --- a/tests/Aspire.Dashboard.Tests/Integration/OtlpHttpServiceTests.cs +++ b/tests/Aspire.Dashboard.Tests/Integration/OtlpHttpServiceTests.cs @@ -34,7 +34,7 @@ public async Task CallService_OtlpHttpEndPoint_BigData_Success() { // Arrange await using var app = IntegrationTestHelpers.CreateDashboardWebApplication(_testOutputHelper); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClient = IntegrationTestHelpers.CreateHttpClient($"http://{app.OtlpServiceHttpEndPointAccessor().EndPoint}"); @@ -44,10 +44,10 @@ public async Task CallService_OtlpHttpEndPoint_BigData_Success() content.Headers.TryAddWithoutValidation("content-type", OtlpHttpEndpointsBuilder.ProtobufContentType); // Act - var responseMessage = await httpClient.PostAsync("/v1/logs", content); + var responseMessage = await httpClient.PostAsync("/v1/logs", content).DefaultTimeout(); responseMessage.EnsureSuccessStatusCode(); - var response = ExportLogsServiceResponse.Parser.ParseFrom(await responseMessage.Content.ReadAsByteArrayAsync()); + var response = ExportLogsServiceResponse.Parser.ParseFrom(await responseMessage.Content.ReadAsByteArrayAsync().DefaultTimeout()); // Assert Assert.Equal(OtlpHttpEndpointsBuilder.ProtobufContentType, responseMessage.Content.Headers.GetValues("content-type").Single()); @@ -60,7 +60,7 @@ public async Task CallService_OtlpHttpEndPoint_ExceedRequestLimit_Failure() { // Arrange await using var app = IntegrationTestHelpers.CreateDashboardWebApplication(_testOutputHelper); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClient = IntegrationTestHelpers.CreateHttpClient($"http://{app.OtlpServiceHttpEndPointAccessor().EndPoint}"); @@ -70,7 +70,7 @@ public async Task CallService_OtlpHttpEndPoint_ExceedRequestLimit_Failure() content.Headers.TryAddWithoutValidation("content-type", OtlpHttpEndpointsBuilder.ProtobufContentType); // Act - var responseMessage = await httpClient.PostAsync("/v1/logs", content); + var responseMessage = await httpClient.PostAsync("/v1/logs", content).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.BadRequest, responseMessage.StatusCode); @@ -106,7 +106,7 @@ public async Task CallService_OtlpHttpEndPoint_RequiredApiKeyMissing_Failure() config[DashboardConfigNames.DashboardOtlpAuthModeName.ConfigKey] = OtlpAuthMode.ApiKey.ToString(); config[DashboardConfigNames.DashboardOtlpPrimaryApiKeyName.ConfigKey] = apiKey; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClient = IntegrationTestHelpers.CreateHttpClient($"http://{app.OtlpServiceHttpEndPointAccessor().EndPoint}"); @@ -114,7 +114,7 @@ public async Task CallService_OtlpHttpEndPoint_RequiredApiKeyMissing_Failure() content.Headers.TryAddWithoutValidation("content-type", OtlpHttpEndpointsBuilder.ProtobufContentType); // Act - var responseMessage = await httpClient.PostAsync("/v1/logs", content); + var responseMessage = await httpClient.PostAsync("/v1/logs", content).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.Unauthorized, responseMessage.StatusCode); @@ -130,7 +130,7 @@ public async Task CallService_OtlpHttpEndPoint_RequiredApiKeyWrong_Failure() config[DashboardConfigNames.DashboardOtlpAuthModeName.ConfigKey] = OtlpAuthMode.ApiKey.ToString(); config[DashboardConfigNames.DashboardOtlpPrimaryApiKeyName.ConfigKey] = apiKey; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClient = IntegrationTestHelpers.CreateHttpClient($"http://{app.OtlpServiceHttpEndPointAccessor().EndPoint}"); @@ -142,7 +142,7 @@ public async Task CallService_OtlpHttpEndPoint_RequiredApiKeyWrong_Failure() requestMessage.Headers.TryAddWithoutValidation(OtlpApiKeyAuthenticationHandler.ApiKeyHeaderName, "WRONG"); // Act - var responseMessage = await httpClient.SendAsync(requestMessage); + var responseMessage = await httpClient.SendAsync(requestMessage).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.Unauthorized, responseMessage.StatusCode); @@ -158,7 +158,7 @@ public async Task CallService_OtlpGrpcEndPoint_RequiredApiKeySent_Success() config[DashboardConfigNames.DashboardOtlpAuthModeName.ConfigKey] = OtlpAuthMode.ApiKey.ToString(); config[DashboardConfigNames.DashboardOtlpPrimaryApiKeyName.ConfigKey] = apiKey; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClient = IntegrationTestHelpers.CreateHttpClient($"http://{app.OtlpServiceHttpEndPointAccessor().EndPoint}"); @@ -170,10 +170,10 @@ public async Task CallService_OtlpGrpcEndPoint_RequiredApiKeySent_Success() requestMessage.Headers.TryAddWithoutValidation(OtlpApiKeyAuthenticationHandler.ApiKeyHeaderName, apiKey); // Act - var responseMessage = await httpClient.SendAsync(requestMessage); + var responseMessage = await httpClient.SendAsync(requestMessage).DefaultTimeout(); responseMessage.EnsureSuccessStatusCode(); - var response = ExportLogsServiceResponse.Parser.ParseFrom(await responseMessage.Content.ReadAsByteArrayAsync()); + var response = ExportLogsServiceResponse.Parser.ParseFrom(await responseMessage.Content.ReadAsByteArrayAsync().DefaultTimeout()); // Assert Assert.Equal(OtlpHttpEndpointsBuilder.ProtobufContentType, responseMessage.Content.Headers.GetValues("content-type").Single()); @@ -192,7 +192,7 @@ public async Task CallService_BrowserEndPoint_Failure() // Change dashboard to HTTPS so the caller can negotiate a HTTP/2 connection. config[DashboardConfigNames.DashboardFrontendUrlName.ConfigKey] = "https://127.0.0.1:0"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClient = IntegrationTestHelpers.CreateHttpClient($"https://{app.FrontendSingleEndPointAccessor().EndPoint}", validationCallback: cert => @@ -204,7 +204,7 @@ public async Task CallService_BrowserEndPoint_Failure() content.Headers.TryAddWithoutValidation("content-type", OtlpHttpEndpointsBuilder.ProtobufContentType); // Act - var responseMessage = await httpClient.PostAsync("/v1/logs", content); + var responseMessage = await httpClient.PostAsync("/v1/logs", content).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.Unauthorized, responseMessage.StatusCode); @@ -222,7 +222,7 @@ public async Task CallService_OtlpHttpEndPoint_UnsupportedContentType_Failure(st { dictionary[DashboardConfigNames.DashboardOtlpHttpUrlName.ConfigKey] = "http://127.0.0.1:0"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); var endpoint = app.OtlpServiceHttpEndPointAccessor(); using var client = new HttpClient { BaseAddress = new Uri($"http://{endpoint.EndPoint}") }; @@ -234,7 +234,7 @@ public async Task CallService_OtlpHttpEndPoint_UnsupportedContentType_Failure(st } // Act - var responseMessage = await client.PostAsync("/v1/logs", content); + var responseMessage = await client.PostAsync("/v1/logs", content).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.UnsupportedMediaType, responseMessage.StatusCode); @@ -250,7 +250,7 @@ public async Task CallService_OtlpHttpEndPoint_UnsupportedMethods_Failure(string { dictionary[DashboardConfigNames.DashboardOtlpHttpUrlName.ConfigKey] = "http://127.0.0.1:0"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); var endpoint = app.OtlpServiceHttpEndPointAccessor(); using var client = new HttpClient { BaseAddress = new Uri($"http://{endpoint.EndPoint}") }; @@ -261,7 +261,7 @@ public async Task CallService_OtlpHttpEndPoint_UnsupportedMethods_Failure(string requestMessage.Content = content; // Act - var responseMessage = await client.SendAsync(requestMessage); + var responseMessage = await client.SendAsync(requestMessage).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.NotFound, responseMessage.StatusCode); @@ -275,7 +275,7 @@ public async Task CallService_OtlpHttpEndPoint_Logs_Success() { dictionary[DashboardConfigNames.DashboardOtlpHttpUrlName.ConfigKey] = "http://127.0.0.1:0"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); var endpoint = app.OtlpServiceHttpEndPointAccessor(); using var client = new HttpClient { BaseAddress = new Uri($"http://{endpoint.EndPoint}") }; @@ -284,7 +284,7 @@ public async Task CallService_OtlpHttpEndPoint_Logs_Success() using var content = new ByteArrayContent(request.ToByteArray()); content.Headers.TryAddWithoutValidation("content-type", OtlpHttpEndpointsBuilder.ProtobufContentType); - var responseMessage = await client.PostAsync("/v1/logs", content); + var responseMessage = await client.PostAsync("/v1/logs", content).DefaultTimeout(); responseMessage.EnsureSuccessStatusCode(); // Act @@ -304,7 +304,7 @@ public async Task CallService_OtlpHttpEndPoint_Traces_Success() { dictionary[DashboardConfigNames.DashboardOtlpHttpUrlName.ConfigKey] = "http://127.0.0.1:0"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); var endpoint = app.OtlpServiceHttpEndPointAccessor(); using var client = new HttpClient { BaseAddress = new Uri($"http://{endpoint.EndPoint}") }; @@ -313,11 +313,11 @@ public async Task CallService_OtlpHttpEndPoint_Traces_Success() using var content = new ByteArrayContent(request.ToByteArray()); content.Headers.TryAddWithoutValidation("content-type", OtlpHttpEndpointsBuilder.ProtobufContentType); - var responseMessage = await client.PostAsync("/v1/traces", content); + var responseMessage = await client.PostAsync("/v1/traces", content).DefaultTimeout(); responseMessage.EnsureSuccessStatusCode(); // Act - var response = ExportTraceServiceResponse.Parser.ParseFrom(await responseMessage.Content.ReadAsByteArrayAsync()); + var response = ExportTraceServiceResponse.Parser.ParseFrom(await responseMessage.Content.ReadAsByteArrayAsync().DefaultTimeout()); // Assert Assert.Equal(OtlpHttpEndpointsBuilder.ProtobufContentType, responseMessage.Content.Headers.GetValues("content-type").Single()); @@ -333,7 +333,7 @@ public async Task CallService_OtlpHttpEndPoint_Metrics_Success() { dictionary[DashboardConfigNames.DashboardOtlpHttpUrlName.ConfigKey] = "http://127.0.0.1:0"; }); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); var endpoint = app.OtlpServiceHttpEndPointAccessor(); using var client = new HttpClient { BaseAddress = new Uri($"http://{endpoint.EndPoint}") }; @@ -342,11 +342,11 @@ public async Task CallService_OtlpHttpEndPoint_Metrics_Success() using var content = new ByteArrayContent(request.ToByteArray()); content.Headers.TryAddWithoutValidation("content-type", OtlpHttpEndpointsBuilder.ProtobufContentType); - var responseMessage = await client.PostAsync("/v1/metrics", content); + var responseMessage = await client.PostAsync("/v1/metrics", content).DefaultTimeout(); responseMessage.EnsureSuccessStatusCode(); // Act - var response = ExportMetricsServiceResponse.Parser.ParseFrom(await responseMessage.Content.ReadAsByteArrayAsync()); + var response = ExportMetricsServiceResponse.Parser.ParseFrom(await responseMessage.Content.ReadAsByteArrayAsync().DefaultTimeout()); // Assert Assert.Equal(OtlpHttpEndpointsBuilder.ProtobufContentType, responseMessage.Content.Headers.GetValues("content-type").Single()); diff --git a/tests/Aspire.Dashboard.Tests/Integration/Playwright/AppBarTests.cs b/tests/Aspire.Dashboard.Tests/Integration/Playwright/AppBarTests.cs index 2cfcaae25cf..a2dd5ab6182 100644 --- a/tests/Aspire.Dashboard.Tests/Integration/Playwright/AppBarTests.cs +++ b/tests/Aspire.Dashboard.Tests/Integration/Playwright/AppBarTests.cs @@ -24,11 +24,11 @@ public async Task AppBar_Change_Theme() // Arrange await RunTestAsync(async page => { - await PlaywrightFixture.GoToHomeAndWaitForDataGridLoad(page); + await PlaywrightFixture.GoToHomeAndWaitForDataGridLoad(page).DefaultTimeout(); - await SetAndVerifyTheme(Dialogs.SettingsDialogSystemTheme, null); // don't guess system theme - await SetAndVerifyTheme(Dialogs.SettingsDialogLightTheme, "light"); - await SetAndVerifyTheme(Dialogs.SettingsDialogDarkTheme, "dark"); + await SetAndVerifyTheme(Dialogs.SettingsDialogSystemTheme, null).DefaultTimeout(); // don't guess system theme + await SetAndVerifyTheme(Dialogs.SettingsDialogLightTheme, "light").DefaultTimeout(); + await SetAndVerifyTheme(Dialogs.SettingsDialogDarkTheme, "dark").DefaultTimeout(); async Task SetAndVerifyTheme(string checkboxText, string? expected) { @@ -70,9 +70,9 @@ public async Task AppBar_Change_Theme_ReloadPage() // Arrange await RunTestAsync(async page => { - await SetAndVerifyTheme(Dialogs.SettingsDialogSystemTheme, null); // don't guess system theme - await SetAndVerifyTheme(Dialogs.SettingsDialogLightTheme, "light"); - await SetAndVerifyTheme(Dialogs.SettingsDialogDarkTheme, "dark"); + await SetAndVerifyTheme(Dialogs.SettingsDialogSystemTheme, null).DefaultTimeout(); // don't guess system theme + await SetAndVerifyTheme(Dialogs.SettingsDialogLightTheme, "light").DefaultTimeout(); + await SetAndVerifyTheme(Dialogs.SettingsDialogDarkTheme, "dark").DefaultTimeout(); async Task SetAndVerifyTheme(string checkboxText, string? expected) { diff --git a/tests/Aspire.Dashboard.Tests/Integration/Playwright/BrowserTokenAuthenticationTests.cs b/tests/Aspire.Dashboard.Tests/Integration/Playwright/BrowserTokenAuthenticationTests.cs index e48b2c49689..9768497ed7a 100644 --- a/tests/Aspire.Dashboard.Tests/Integration/Playwright/BrowserTokenAuthenticationTests.cs +++ b/tests/Aspire.Dashboard.Tests/Integration/Playwright/BrowserTokenAuthenticationTests.cs @@ -5,6 +5,7 @@ using Aspire.Dashboard.Tests.Integration.Playwright.Infrastructure; using Aspire.Hosting; using Aspire.Workload.Tests; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.Playwright; using Xunit; @@ -34,21 +35,22 @@ public async Task BrowserToken_LoginPage_Success_RedirectToResources() await RunTestAsync(async page => { // Act - var response = await page.GotoAsync("/"); + var response = await page.GotoAsync("/").DefaultTimeout(); var uri = new Uri(response!.Url); Assert.Equal("/login?returnUrl=%2F", uri.PathAndQuery); var tokenTextBox = page.GetByRole(AriaRole.Textbox); - await tokenTextBox.FillAsync("VALID_TOKEN"); + await tokenTextBox.FillAsync("VALID_TOKEN").DefaultTimeout(); var submitButton = page.GetByRole(AriaRole.Button); - await submitButton.ClickAsync(); + await submitButton.ClickAsync().DefaultTimeout(); // Assert await Assertions .Expect(page.GetByText(MockDashboardClient.TestResource1.DisplayName)) - .ToBeVisibleAsync(); + .ToBeVisibleAsync() + .DefaultTimeout(); }); } @@ -59,21 +61,22 @@ public async Task BrowserToken_LoginPage_Failure_DisplayFailureMessage() await RunTestAsync(async page => { // Act - var response = await page.GotoAsync("/"); + var response = await page.GotoAsync("/").DefaultTimeout(); var uri = new Uri(response!.Url); Assert.Equal("/login?returnUrl=%2F", uri.PathAndQuery); var tokenTextBox = page.GetByRole(AriaRole.Textbox); - await tokenTextBox.FillAsync("INVALID_TOKEN"); + await tokenTextBox.FillAsync("INVALID_TOKEN").DefaultTimeout(); var submitButton = page.GetByRole(AriaRole.Button); - await submitButton.ClickAsync(); + await submitButton.ClickAsync().DefaultTimeout(); // Assert await Assertions .Expect(page.GetByText("Invalid token")) - .ToBeVisibleAsync(); + .ToBeVisibleAsync() + .DefaultTimeout(); }); } @@ -84,12 +87,13 @@ public async Task BrowserToken_QueryStringToken_Success_RestrictToResources() await RunTestAsync(async page => { // Act - await page.GotoAsync("/login?t=VALID_TOKEN"); + await page.GotoAsync("/login?t=VALID_TOKEN").DefaultTimeout(); // Assert await Assertions .Expect(page.GetByText(MockDashboardClient.TestResource1.DisplayName)) - .ToBeVisibleAsync(); + .ToBeVisibleAsync() + .DefaultTimeout(); }); } @@ -100,10 +104,10 @@ public async Task BrowserToken_QueryStringToken_Failure_DisplayLoginPage() await RunTestAsync(async page => { // Act - await page.GotoAsync("/login?t=INVALID_TOKEN"); + await page.GotoAsync("/login?t=INVALID_TOKEN").DefaultTimeout(); var submitButton = page.GetByRole(AriaRole.Button); - var name = await submitButton.GetAttributeAsync("name"); + var name = await submitButton.GetAttributeAsync("name").DefaultTimeout(); // Assert Assert.Equal("submit-token", name); diff --git a/tests/Aspire.Dashboard.Tests/Integration/ResponseCompressionTests.cs b/tests/Aspire.Dashboard.Tests/Integration/ResponseCompressionTests.cs index 0d6ef83f6a2..f019ee55294 100644 --- a/tests/Aspire.Dashboard.Tests/Integration/ResponseCompressionTests.cs +++ b/tests/Aspire.Dashboard.Tests/Integration/ResponseCompressionTests.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Aspire.Dashboard.Utils; +using Microsoft.AspNetCore.InternalTesting; using System.Net; using System.Net.Http.Headers; using Xunit; @@ -16,7 +17,7 @@ public async Task Html_Responses_Are_Not_Compressed() { // Arrange await using var app = IntegrationTestHelpers.CreateDashboardWebApplication(testOutputHelper); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClientHandler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.None }; using var client = new HttpClient(httpClientHandler) { BaseAddress = new Uri($"http://{app.FrontendSingleEndPointAccessor().EndPoint}") }; @@ -24,7 +25,7 @@ public async Task Html_Responses_Are_Not_Compressed() // Act 1 var request = new HttpRequestMessage(HttpMethod.Get, DashboardUrls.StructuredLogsBasePath); request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("br")); - var response = await client.SendAsync(request); + var response = await client.SendAsync(request).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -38,7 +39,7 @@ public async Task Static_Asset_Responses_Are_Compressed(string path) { // Arrange await using var app = IntegrationTestHelpers.CreateDashboardWebApplication(testOutputHelper); - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var httpClientHandler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.None }; using var client = new HttpClient(httpClientHandler) { BaseAddress = new Uri($"http://{app.FrontendSingleEndPointAccessor().EndPoint}") }; @@ -46,7 +47,7 @@ public async Task Static_Asset_Responses_Are_Compressed(string path) // Act 1 var request = new HttpRequestMessage(HttpMethod.Get, path); request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("br")); - var response = await client.SendAsync(request); + var response = await client.SendAsync(request).DefaultTimeout(); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); diff --git a/tests/Aspire.Dashboard.Tests/Integration/StartupTests.cs b/tests/Aspire.Dashboard.Tests/Integration/StartupTests.cs index cf73ffaf352..ad3b9e5ab1c 100644 --- a/tests/Aspire.Dashboard.Tests/Integration/StartupTests.cs +++ b/tests/Aspire.Dashboard.Tests/Integration/StartupTests.cs @@ -37,7 +37,7 @@ public async Task EndPointAccessors_AppStarted_EndPointPortsAssigned() }); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); // Assert Assert.Collection(app.FrontendEndPointsAccessor, @@ -69,7 +69,7 @@ public async Task EndPointAccessors_AppStarted_IPv4OrIPv6() }); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); // Assert, Assert.Collection(app.FrontendEndPointsAccessor, @@ -137,7 +137,7 @@ public async Task Configuration_ConfigFilePathDoesntExist_Error() { data[DashboardConfigNames.DashboardConfigFilePathName.ConfigKey] = configFilePath; }); - }); + }).DefaultTimeout(); // Assert Assert.Contains(configFilePath, ex.Message); @@ -182,7 +182,7 @@ public async Task Configuration_FileConfigDirectoryReloadsChanges_Success() const string initialFrontendBrowserToken = "InitialSecretContent"; const string changedFrontendBrowserToken = "NewSecretContent"; var fileConfigDirectory = Directory.CreateTempSubdirectory(); - var browserTokenConfigFile = await CreateBrowserTokenConfigFileAsync(fileConfigDirectory, initialFrontendBrowserToken); + var browserTokenConfigFile = await CreateBrowserTokenConfigFileAsync(fileConfigDirectory, initialFrontendBrowserToken).DefaultTimeout(); try { var loggerFactory = IntegrationTestHelpers.CreateLoggerFactory(testOutputHelper); @@ -203,7 +203,7 @@ public async Task Configuration_FileConfigDirectoryReloadsChanges_Success() var initialBrowserTokenProvidedByConfiguration = localBuilder?.Configuration[DashboardConfigNames.DashboardFrontendBrowserTokenName.ConfigKey]; // update the browser token's config file and get the new value - await File.WriteAllTextAsync(browserTokenConfigFile, changedFrontendBrowserToken); + await File.WriteAllTextAsync(browserTokenConfigFile, changedFrontendBrowserToken).DefaultTimeout(); // Assert Assert.Equal(initialFrontendBrowserToken, initialBrowserTokenProvidedByConfiguration); @@ -234,7 +234,7 @@ public async Task Configuration_FileConfigDirectoryDoesntExist_Error() { data[DashboardConfigNames.DashboardFileConfigDirectoryName.ConfigKey] = fileConfigDirectory; }); - }); + }).DefaultTimeout(); // Assert Assert.Contains(fileConfigDirectory, ex.Message); @@ -252,7 +252,7 @@ public async Task Configuration_OptionsMonitor_CanReadConfiguration() }); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); // Assert Assert.Equal(OtlpAuthMode.ApiKey, app.DashboardOptionsMonitor.CurrentValue.Otlp.AuthMode); @@ -277,7 +277,7 @@ await ServerRetryHelper.BindPortWithRetry(async port => }); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); }, NullLogger.Instance); // Assert @@ -296,20 +296,20 @@ await ServerRetryHelper.BindPortWithRetry(async port => BaseAddress = new Uri($"https://{app.FrontendSingleEndPointAccessor().EndPoint}") }; var request = new HttpRequestMessage(HttpMethod.Get, "/"); - var response = await httpClient.SendAsync(request); + var response = await httpClient.SendAsync(request).DefaultTimeout(); response.EnsureSuccessStatusCode(); // Check OTLP service using var channel = IntegrationTestHelpers.CreateGrpcChannel($"https://{app.FrontendSingleEndPointAccessor().EndPoint}", testOutputHelper); var client = new LogsService.LogsServiceClient(channel); - var serviceResponse = await client.ExportAsync(new ExportLogsServiceRequest()); + var serviceResponse = await client.ExportAsync(new ExportLogsServiceRequest()).ResponseAsync.DefaultTimeout(); Assert.Equal(0, serviceResponse.PartialSuccess.RejectedLogRecords); } finally { if (app is not null) { - await app.DisposeAsync(); + await app.DisposeAsync().DefaultTimeout(); } } } @@ -334,7 +334,7 @@ await ServerRetryHelper.BindPortWithRetry(async port => testSink: testSink); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); }, NullLogger.Instance); // Assert @@ -359,7 +359,7 @@ await ServerRetryHelper.BindPortWithRetry(async port => { if (app is not null) { - await app.DisposeAsync(); + await app.DisposeAsync().DefaultTimeout(); } } } @@ -384,7 +384,7 @@ await ServerRetryHelper.BindPortWithRetry(async port => testSink: testSink); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); }, NullLogger.Instance); // Assert @@ -397,7 +397,7 @@ await ServerRetryHelper.BindPortWithRetry(async port => BaseAddress = new Uri($"http://{app.FrontendSingleEndPointAccessor().EndPoint}") }; var request = new HttpRequestMessage(HttpMethod.Get, "/"); - var responseMessage = await httpClient.SendAsync(request); + var responseMessage = await httpClient.SendAsync(request).DefaultTimeout(); responseMessage.EnsureSuccessStatusCode(); // Check OTLP service @@ -407,7 +407,7 @@ await ServerRetryHelper.BindPortWithRetry(async port => responseMessage = await httpClient.PostAsync("/v1/logs", content); responseMessage.EnsureSuccessStatusCode(); - var response = ExportLogsServiceResponse.Parser.ParseFrom(await responseMessage.Content.ReadAsByteArrayAsync()); + var response = ExportLogsServiceResponse.Parser.ParseFrom(await responseMessage.Content.ReadAsByteArrayAsync().DefaultTimeout()); Assert.Equal(OtlpHttpEndpointsBuilder.ProtobufContentType, responseMessage.Content.Headers.GetValues("content-type").Single()); Assert.False(responseMessage.Headers.Contains("content-security-policy")); @@ -417,7 +417,7 @@ await ServerRetryHelper.BindPortWithRetry(async port => { if (app is not null) { - await app.DisposeAsync(); + await app.DisposeAsync().DefaultTimeout(); } } } @@ -451,7 +451,7 @@ public async Task Configuration_AllowAnonymous_NoError() }); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); // Assert Assert.Equal(FrontendAuthMode.Unsecured, app.DashboardOptionsMonitor.CurrentValue.Frontend.AuthMode); @@ -492,7 +492,7 @@ public async Task Configuration_Logging_OverrideDefaults() clearLogFilterRules: false); // Assert - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); var options = app.Services.GetRequiredService>(); @@ -518,7 +518,7 @@ public async Task Configuration_Logging_FileConfig_OverrideDefaults() } } }; - await File.WriteAllTextAsync(configFilePath, configJson.ToString()); + await File.WriteAllTextAsync(configFilePath, configJson.ToString()).DefaultTimeout(); try { @@ -531,7 +531,7 @@ public async Task Configuration_Logging_FileConfig_OverrideDefaults() clearLogFilterRules: false); // Assert - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); var options = app.Services.GetRequiredService>(); @@ -553,7 +553,7 @@ public async Task LogOutput_DynamicPort_PortResolvedInLogs() await using var app = IntegrationTestHelpers.CreateDashboardWebApplication(testOutputHelper, testSink: testSink); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); // Assert var l = testSink.Writes.Where(w => w.LoggerName == typeof(DashboardWebApplication).FullName).ToList(); @@ -623,14 +623,14 @@ await ServerRetryHelper.BindPortsWithRetry(async ports => }, testSink: testSink); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); }, NullLogger.Instance, portCount: 3); } finally { if (app is not null) { - await app.DisposeAsync(); + await app.DisposeAsync().DefaultTimeout(); } } @@ -685,12 +685,12 @@ public async Task EndPointAccessors_AppStarted_BrowserGet_Success() await using var app = IntegrationTestHelpers.CreateDashboardWebApplication(testOutputHelper); // Act - await app.StartAsync(); + await app.StartAsync().DefaultTimeout(); using var client = new HttpClient { BaseAddress = new Uri($"http://{app.FrontendSingleEndPointAccessor().EndPoint}") }; // Act - var response = await client.GetAsync("/"); + var response = await client.GetAsync("/").DefaultTimeout(); // Assert response.EnsureSuccessStatusCode(); diff --git a/tests/Aspire.Dashboard.Tests/LocalBrowserStorageTests.cs b/tests/Aspire.Dashboard.Tests/LocalBrowserStorageTests.cs index 0740cc6e200..d93c4cab8bc 100644 --- a/tests/Aspire.Dashboard.Tests/LocalBrowserStorageTests.cs +++ b/tests/Aspire.Dashboard.Tests/LocalBrowserStorageTests.cs @@ -5,6 +5,7 @@ using Aspire.Dashboard.Model.BrowserStorage; using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; using Microsoft.AspNetCore.DataProtection; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.JSInterop; using Xunit; @@ -32,7 +33,7 @@ public async Task SetUnprotectedAsync_JSInvokedWithJson(object? value, string re var localStorage = CreateBrowserLocalStorage(testJsonRuntime); // Act - await localStorage.SetUnprotectedAsync("MyKey", value); + await localStorage.SetUnprotectedAsync("MyKey", value).DefaultTimeout(); // Assert Assert.Equal("localStorage.setItem", identifier); @@ -57,7 +58,7 @@ public async Task GetUnprotectedAsync_HasValue_Success() var localStorage = CreateBrowserLocalStorage(testJsonRuntime); // Act - var result = await localStorage.GetUnprotectedAsync("MyKey"); + var result = await localStorage.GetUnprotectedAsync("MyKey").DefaultTimeout(); // Assert Assert.True(result.Success); @@ -83,7 +84,7 @@ public async Task GetUnprotectedAsync_NoValue_Failure() var localStorage = CreateBrowserLocalStorage(testJsonRuntime); // Act - var result = await localStorage.GetUnprotectedAsync("MyKey"); + var result = await localStorage.GetUnprotectedAsync("MyKey").DefaultTimeout(); // Assert Assert.False(result.Success); @@ -108,7 +109,7 @@ public async Task GetUnprotectedAsync_InvalidValue_Failure() var localStorage = CreateBrowserLocalStorage(testJsonRuntime); // Act - var result = await localStorage.GetUnprotectedAsync("MyKey"); + var result = await localStorage.GetUnprotectedAsync("MyKey").DefaultTimeout(); // Assert Assert.False(result.Success); diff --git a/tests/Aspire.Dashboard.Tests/Middleware/ValidateTokenMiddlewareTests.cs b/tests/Aspire.Dashboard.Tests/Middleware/ValidateTokenMiddlewareTests.cs index 77add73762e..e887dba46e4 100644 --- a/tests/Aspire.Dashboard.Tests/Middleware/ValidateTokenMiddlewareTests.cs +++ b/tests/Aspire.Dashboard.Tests/Middleware/ValidateTokenMiddlewareTests.cs @@ -5,6 +5,7 @@ using Aspire.Dashboard.Model; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -17,48 +18,48 @@ public class ValidateTokenMiddlewareTests [Fact] public async Task ValidateToken_NotBrowserTokenAuth_RedirectedToHomepage() { - using var host = await SetUpHostAsync(FrontendAuthMode.Unsecured, string.Empty); - var response = await host.GetTestClient().GetAsync("/login?t=test"); + using var host = await SetUpHostAsync(FrontendAuthMode.Unsecured, string.Empty).DefaultTimeout(); + var response = await host.GetTestClient().GetAsync("/login?t=test").DefaultTimeout(); Assert.Equal("/", response.Headers.Location?.OriginalString); } [Fact] public async Task ValidateToken_NotBrowserTokenAuth_RedirectedToReturnUrl() { - using var host = await SetUpHostAsync(FrontendAuthMode.Unsecured, string.Empty); - var response = await host.GetTestClient().GetAsync("/login?t=test&returnUrl=/test"); + using var host = await SetUpHostAsync(FrontendAuthMode.Unsecured, string.Empty).DefaultTimeout(); + var response = await host.GetTestClient().GetAsync("/login?t=test&returnUrl=/test").DefaultTimeout(); Assert.Equal("/test", response.Headers.Location?.OriginalString); } [Fact] public async Task ValidateToken_BrowserTokenAuth_WrongToken_RedirectsToLogin() { - using var host = await SetUpHostAsync(FrontendAuthMode.BrowserToken, "token"); - var response = await host.GetTestClient().GetAsync("/login?t=wrong"); + using var host = await SetUpHostAsync(FrontendAuthMode.BrowserToken, "token").DefaultTimeout(); + var response = await host.GetTestClient().GetAsync("/login?t=wrong").DefaultTimeout(); Assert.Equal("/login", response.Headers.Location?.OriginalString); } [Fact] public async Task ValidateToken_BrowserTokenAuth_WrongToken_RedirectsToLogin_WithReturnUrl() { - using var host = await SetUpHostAsync(FrontendAuthMode.BrowserToken, "token"); - var response = await host.GetTestClient().GetAsync("/login?t=wrong&returnUrl=/test"); + using var host = await SetUpHostAsync(FrontendAuthMode.BrowserToken, "token").DefaultTimeout(); + var response = await host.GetTestClient().GetAsync("/login?t=wrong&returnUrl=/test").DefaultTimeout(); Assert.Equal("/login?returnUrl=%2ftest", response.Headers.Location?.OriginalString); } [Fact] public async Task ValidateToken_BrowserTokenAuth_RightToken_RedirectsToHome() { - using var host = await SetUpHostAsync(FrontendAuthMode.BrowserToken, "token"); - var response = await host.GetTestClient().GetAsync("/login?t=token"); + using var host = await SetUpHostAsync(FrontendAuthMode.BrowserToken, "token").DefaultTimeout(); + var response = await host.GetTestClient().GetAsync("/login?t=token").DefaultTimeout(); Assert.Equal("/", response.Headers.Location?.OriginalString); } [Fact] public async Task ValidateToken_BrowserTokenAuth_RightToken_RedirectsToReturnUrl() { - using var host = await SetUpHostAsync(FrontendAuthMode.BrowserToken, "token"); - var response = await host.GetTestClient().GetAsync("/login?t=token&returnUrl=/test"); + using var host = await SetUpHostAsync(FrontendAuthMode.BrowserToken, "token").DefaultTimeout(); + var response = await host.GetTestClient().GetAsync("/login?t=token&returnUrl=/test").DefaultTimeout(); Assert.Equal("/test", response.Headers.Location?.OriginalString); } diff --git a/tests/Aspire.Dashboard.Tests/Model/DashboardClientTests.cs b/tests/Aspire.Dashboard.Tests/Model/DashboardClientTests.cs index 3e5c76cefce..a9797e78b2e 100644 --- a/tests/Aspire.Dashboard.Tests/Model/DashboardClientTests.cs +++ b/tests/Aspire.Dashboard.Tests/Model/DashboardClientTests.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Xunit; +using Microsoft.AspNetCore.InternalTesting; namespace Aspire.Dashboard.Tests.Model; @@ -49,7 +50,7 @@ public async Task SubscribeResources_OnCancel_ChannelRemoved() Assert.Equal(0, instance.OutgoingResourceSubscriberCount); - var (_, subscription) = await client.SubscribeResourcesAsync(CancellationToken.None); + var (_, subscription) = await client.SubscribeResourcesAsync(CancellationToken.None).DefaultTimeout(); Assert.Equal(1, instance.OutgoingResourceSubscriberCount); @@ -60,9 +61,9 @@ public async Task SubscribeResources_OnCancel_ChannelRemoved() } }); - await cts.CancelAsync(); + cts.Cancel(); - await TaskHelpers.WaitIgnoreCancelAsync(readTask); + await TaskHelpers.WaitIgnoreCancelAsync(readTask).DefaultTimeout(); Assert.Equal(0, instance.OutgoingResourceSubscriberCount); } @@ -77,7 +78,7 @@ public async Task SubscribeResources_OnDispose_ChannelRemoved() Assert.Equal(0, instance.OutgoingResourceSubscriberCount); - var (_, subscription) = await client.SubscribeResourcesAsync(CancellationToken.None); + var (_, subscription) = await client.SubscribeResourcesAsync(CancellationToken.None).DefaultTimeout(); Assert.Equal(1, instance.OutgoingResourceSubscriberCount); @@ -88,11 +89,11 @@ public async Task SubscribeResources_OnDispose_ChannelRemoved() } }); - await instance.DisposeAsync(); + await instance.DisposeAsync().DefaultTimeout(); Assert.Equal(0, instance.OutgoingResourceSubscriberCount); - await TaskHelpers.WaitIgnoreCancelAsync(readTask); + await TaskHelpers.WaitIgnoreCancelAsync(readTask).DefaultTimeout(); } [Fact] @@ -100,9 +101,9 @@ public async Task SubscribeResources_ThrowsIfDisposed() { await using IDashboardClient client = CreateResourceServiceClient(); - await client.DisposeAsync(); + await client.DisposeAsync().DefaultTimeout(); - await Assert.ThrowsAsync(() => client.SubscribeResourcesAsync(CancellationToken.None)); + await Assert.ThrowsAsync(() => client.SubscribeResourcesAsync(CancellationToken.None)).DefaultTimeout(); } [Fact] @@ -115,11 +116,11 @@ public async Task SubscribeResources_IncreasesSubscriberCount() Assert.Equal(0, instance.OutgoingResourceSubscriberCount); - _ = await client.SubscribeResourcesAsync(CancellationToken.None); + _ = await client.SubscribeResourcesAsync(CancellationToken.None).DefaultTimeout(); Assert.Equal(1, instance.OutgoingResourceSubscriberCount); - await instance.DisposeAsync(); + await instance.DisposeAsync().DefaultTimeout(); Assert.Equal(0, instance.OutgoingResourceSubscriberCount); } @@ -144,7 +145,7 @@ public async Task SubscribeResources_HasInitialData_InitialDataReturned() CreatedAt = Timestamp.FromDateTime(DateTime.UtcNow), }]); - var (initialData, subscription) = await subscribeTask; + var (initialData, subscription) = await subscribeTask.DefaultTimeout(); Assert.Single(initialData); } diff --git a/tests/Aspire.Dashboard.Tests/OtlpApiKeyAuthenticationHandlerTests.cs b/tests/Aspire.Dashboard.Tests/OtlpApiKeyAuthenticationHandlerTests.cs index 7cd5c6d360b..7827da851ac 100644 --- a/tests/Aspire.Dashboard.Tests/OtlpApiKeyAuthenticationHandlerTests.cs +++ b/tests/Aspire.Dashboard.Tests/OtlpApiKeyAuthenticationHandlerTests.cs @@ -6,6 +6,7 @@ using Aspire.Dashboard.Configuration; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Xunit; @@ -18,10 +19,10 @@ public class OtlpApiKeyAuthenticationHandlerTests public async Task AuthenticateAsync_NoHeader_Failure() { // Arrange - var handler = await CreateAuthHandlerAsync(primaryApiKey: "abc", secondaryApiKey: null, otlpApiKeyHeader: null); + var handler = await CreateAuthHandlerAsync(primaryApiKey: "abc", secondaryApiKey: null, otlpApiKeyHeader: null).DefaultTimeout(); // Act - var result = await handler.AuthenticateAsync(); + var result = await handler.AuthenticateAsync().DefaultTimeout(); // Assert Assert.NotNull(result.Failure); @@ -32,10 +33,10 @@ public async Task AuthenticateAsync_NoHeader_Failure() public async Task AuthenticateAsync_BigApiKeys_NoMatch_Failure() { // Arrange - var handler = await CreateAuthHandlerAsync(primaryApiKey: new string('!', 1000), secondaryApiKey: null, otlpApiKeyHeader: new string('!', 999)); + var handler = await CreateAuthHandlerAsync(primaryApiKey: new string('!', 1000), secondaryApiKey: null, otlpApiKeyHeader: new string('!', 999)).DefaultTimeout(); // Act - var result = await handler.AuthenticateAsync(); + var result = await handler.AuthenticateAsync().DefaultTimeout(); // Assert Assert.NotNull(result.Failure); @@ -46,10 +47,10 @@ public async Task AuthenticateAsync_BigApiKeys_NoMatch_Failure() public async Task AuthenticateAsync_BigApiKeys_Match_Success() { // Arrange - var handler = await CreateAuthHandlerAsync(primaryApiKey: new string('!', 1000), secondaryApiKey: null, otlpApiKeyHeader: new string('!', 1000)); + var handler = await CreateAuthHandlerAsync(primaryApiKey: new string('!', 1000), secondaryApiKey: null, otlpApiKeyHeader: new string('!', 1000)).DefaultTimeout(); // Act - var result = await handler.AuthenticateAsync(); + var result = await handler.AuthenticateAsync().DefaultTimeout(); // Assert Assert.Null(result.Failure); @@ -63,10 +64,10 @@ public async Task AuthenticateAsync_BigApiKeys_Match_Success() public async Task AuthenticateAsync_MatchHeader_Success(string primaryApiKey, string? secondaryApiKey, string otlpApiKeyHeader, bool success) { // Arrange - var handler = await CreateAuthHandlerAsync(primaryApiKey, secondaryApiKey, otlpApiKeyHeader); + var handler = await CreateAuthHandlerAsync(primaryApiKey, secondaryApiKey, otlpApiKeyHeader).DefaultTimeout(); // Act - var result = await handler.AuthenticateAsync(); + var result = await handler.AuthenticateAsync().DefaultTimeout(); // Assert Assert.Equal(success, result.Failure == null); diff --git a/tests/Aspire.Dashboard.Tests/ResourceOutgoingPeerResolverTests.cs b/tests/Aspire.Dashboard.Tests/ResourceOutgoingPeerResolverTests.cs index 64d431c765c..5509fa42096 100644 --- a/tests/Aspire.Dashboard.Tests/ResourceOutgoingPeerResolverTests.cs +++ b/tests/Aspire.Dashboard.Tests/ResourceOutgoingPeerResolverTests.cs @@ -5,6 +5,7 @@ using System.Threading.Channels; using Aspire.Dashboard.Model; using Aspire.Tests.Shared.DashboardModel; +using Microsoft.AspNetCore.InternalTesting; using Xunit; namespace Aspire.Dashboard.Tests; @@ -138,17 +139,17 @@ public async Task OnPeerChanges_DataUpdates_EventRaised() GetChanges())); // Assert 1 - readValue = await resultChannel.Reader.ReadAsync(); + readValue = await resultChannel.Reader.ReadAsync().DefaultTimeout(); Assert.Equal(1, readValue); // Act 2 await sourceChannel.Writer.WriteAsync(new ResourceViewModelChange(ResourceViewModelChangeType.Upsert, CreateResource("test2"))); // Assert 2 - readValue = await resultChannel.Reader.ReadAsync(); + readValue = await resultChannel.Reader.ReadAsync().DefaultTimeout(); Assert.Equal(2, readValue); - await resolver.DisposeAsync(); + await resolver.DisposeAsync().DefaultTimeout(); async IAsyncEnumerable> GetChanges([EnumeratorCancellation] CancellationToken cancellationToken = default) { diff --git a/tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/LogTests.cs b/tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/LogTests.cs index 5d30846c64e..0630b0edd8a 100644 --- a/tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/LogTests.cs +++ b/tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/LogTests.cs @@ -8,6 +8,7 @@ using Aspire.Dashboard.Otlp.Storage; using Aspire.Dashboard.Tests.Integration; using Google.Protobuf.Collections; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.Extensions.Logging; using OpenTelemetry.Proto.Logs.V1; using Xunit; @@ -434,7 +435,7 @@ public async Task Subscriptions_AddLog() // Assert 1 Assert.Equal(0, addContext1.FailureCount); - await newApplicationsTcs.Task; + await newApplicationsTcs.Task.DefaultTimeout(); var applications = repository.GetApplications(); Assert.Collection(applications, @@ -469,7 +470,7 @@ public async Task Subscriptions_AddLog() } }); - await newLogsTcs.Task; + await newLogsTcs.Task.DefaultTimeout(); // Assert 2 Assert.Equal(0, addContext2.FailureCount); @@ -563,10 +564,10 @@ public async Task Subscription_RaisedFromDifferentContext_InitialContextPreserve }); } - await task; + await task.DefaultTimeout(); // Assert - var callbackValue = await tcs.Task; + var callbackValue = await tcs.Task.DefaultTimeout(); Assert.Equal("CustomValue", callbackValue); } @@ -704,7 +705,7 @@ public async Task Subscription_MultipleUpdates_MinExecuteIntervalApplied() }); // Assert - var read1 = await resultChannel.Reader.ReadAsync(); + var read1 = await resultChannel.Reader.ReadAsync().DefaultTimeout(); Assert.Equal(1, read1); logger.LogInformation("Received log 1 callback"); @@ -725,7 +726,7 @@ public async Task Subscription_MultipleUpdates_MinExecuteIntervalApplied() } }); - var read2 = await resultChannel.Reader.ReadAsync(); + var read2 = await resultChannel.Reader.ReadAsync().DefaultTimeout(); Assert.Equal(2, read2); logger.LogInformation("Received log 2 callback");