From 2b5ab7c88faa54c35b6ccedfc76987c625e44598 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sat, 14 Sep 2024 10:45:33 +0800 Subject: [PATCH] More logging and fix --- .../Components/Controls/LogViewer.razor.cs | 11 +++++++++-- .../Components/Pages/ConsoleLogs.razor.cs | 3 +++ .../Pages/ConsoleLogsTests.cs | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Aspire.Dashboard/Components/Controls/LogViewer.razor.cs b/src/Aspire.Dashboard/Components/Controls/LogViewer.razor.cs index 0b990f44906..0d3e1e8a5ad 100644 --- a/src/Aspire.Dashboard/Components/Controls/LogViewer.razor.cs +++ b/src/Aspire.Dashboard/Components/Controls/LogViewer.razor.cs @@ -27,10 +27,13 @@ public sealed partial class LogViewer public required BrowserTimeProvider TimeProvider { get; init; } [Inject] - public required DimensionManager DimensionManager { get; set; } + public required DimensionManager DimensionManager { get; init; } [Inject] - public required IOptions Options { get; set; } + public required ILogger Logger { get; init; } + + [Inject] + public required IOptions Options { get; init; } internal LogEntries LogEntries { get; set; } = null!; @@ -66,6 +69,8 @@ private void OnBrowserResize(object? o, EventArgs args) internal async Task SetLogSourceAsync(string resourceName, IAsyncEnumerable> batches, bool convertTimestampsFromUtc = true) { + Logger.LogDebug("Setting log source to {ResourceName}.", resourceName); + ResourceName = resourceName; System.Diagnostics.Debug.Assert(LogEntries.GetEntries().Count == 0, "Expecting zero log entries"); @@ -108,6 +113,8 @@ private string GetDisplayTimestamp(DateTimeOffset timestamp) internal async Task ClearLogsAsync() { + Logger.LogDebug("Clearing logs for {ResourceName}.", ResourceName); + await _cancellationSeries.ClearAsync(); _applicationChanged = true; diff --git a/src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs b/src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs index e6f738b9654..f43f3ee906a 100644 --- a/src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs +++ b/src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs @@ -290,6 +290,7 @@ private async ValueTask LoadLogsAsync() { try { + Logger.LogDebug("Waiting for console logs subscription {ResourceName} to finished.", resourceSubscriptionName); await task; } finally @@ -298,6 +299,8 @@ private async ValueTask LoadLogsAsync() _subscriptionResourceName = null; PageViewModel.Status = Loc[nameof(Dashboard.Resources.ConsoleLogs.ConsoleLogsFinishedWatchingLogs)]; + + await InvokeAsync(StateHasChanged); } }); } diff --git a/tests/Aspire.Dashboard.Components.Tests/Pages/ConsoleLogsTests.cs b/tests/Aspire.Dashboard.Components.Tests/Pages/ConsoleLogsTests.cs index b7b617b3945..1abc8fe1718 100644 --- a/tests/Aspire.Dashboard.Components.Tests/Pages/ConsoleLogsTests.cs +++ b/tests/Aspire.Dashboard.Components.Tests/Pages/ConsoleLogsTests.cs @@ -61,6 +61,10 @@ public void ResourceName_MultiRender_SubscribeConsoleLogsOnce() var instance = cut.Instance; var logger = Services.GetRequiredService>(); + var loc = Services.GetRequiredService>(); + + logger.LogInformation("Console log page is waiting for resource."); + cut.WaitForState(() => instance.PageViewModel.Status == loc[nameof(Resources.ConsoleLogs.ConsoleLogsLoadingResources)]); var testResource = CreateResourceViewModel("test-resource", KnownResourceState.Running); resourceChannel.Writer.TryWrite([ @@ -70,6 +74,7 @@ public void ResourceName_MultiRender_SubscribeConsoleLogsOnce() // Assert logger.LogInformation("Waiting for selected resource."); cut.WaitForState(() => instance.PageViewModel.SelectedResource == testResource); + cut.WaitForState(() => instance.PageViewModel.Status == loc[nameof(Resources.ConsoleLogs.ConsoleLogsWatchingLogs)]); // Ensure component is rendered again. cut.SetParametersAndRender(builder => { }); @@ -78,7 +83,6 @@ public void ResourceName_MultiRender_SubscribeConsoleLogsOnce() consoleLogsChannel.Writer.Complete(); logger.LogInformation("Waiting for finish message."); - var loc = Services.GetRequiredService>(); cut.WaitForState(() => instance.PageViewModel.Status == loc[nameof(Resources.ConsoleLogs.ConsoleLogsFinishedWatchingLogs)]); Assert.Equal("test-resource", Assert.Single(subscribedResourceNames));