diff --git a/playground/kafka/Consumer/ConsumerWorker.cs b/playground/kafka/Consumer/ConsumerWorker.cs index f2f587dbbab..c344914dd6d 100644 --- a/playground/kafka/Consumer/ConsumerWorker.cs +++ b/playground/kafka/Consumer/ConsumerWorker.cs @@ -19,6 +19,10 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) try { result = consumer.Consume(TimeSpan.FromSeconds(1)); + if (result is not null) + { + logger.LogInformation($"Consumed message [{result.Message?.Key}] = {result.Message?.Value}"); + } } catch (ConsumeException ex) when (ex.Error.Code == ErrorCode.UnknownTopicOrPart) { diff --git a/playground/withdockerfile/WithDockerfile.AppHost/Program.cs b/playground/withdockerfile/WithDockerfile.AppHost/Program.cs index 05130224a90..240a77e541a 100644 --- a/playground/withdockerfile/WithDockerfile.AppHost/Program.cs +++ b/playground/withdockerfile/WithDockerfile.AppHost/Program.cs @@ -9,7 +9,8 @@ builder.AddDockerfile("mycontainer", "qots") .WithBuildArg("GO_VERSION", goVersion) - .WithBuildSecret("SECRET_ASENV", secret); + .WithBuildSecret("SECRET_ASENV", secret) + .WithEnvironment("DOCKER_BUILDKIT", "1"); #if !SKIP_DASHBOARD_REFERENCE // This project is only added in playground projects to support development/debugging diff --git a/tests/Aspire.Hosting.Tests/Utils/LoggerNotificationExtensions.cs b/tests/Aspire.Hosting.Tests/Utils/LoggerNotificationExtensions.cs index d52bae4bb62..69dec7d2103 100644 --- a/tests/Aspire.Hosting.Tests/Utils/LoggerNotificationExtensions.cs +++ b/tests/Aspire.Hosting.Tests/Utils/LoggerNotificationExtensions.cs @@ -68,6 +68,39 @@ public static Task WaitForTextAsync(this DistributedApplication app, Predicate + /// Waits for all the specified texts to be logged. + /// + /// The instance to watch. + /// Any text to wait for. + /// An optional resource name to filter the logs for. + /// The cancellation token. + /// + public static async Task WaitForAllTextAsync(this DistributedApplication app, IEnumerable logTexts, string? resourceName = null, CancellationToken cancellationToken = default) + { + var table = logTexts.ToList(); + try + { + await app.WaitForTextAsync((log) => + { + foreach (var text in table) + { + if (log.Contains(text)) + { + table.Remove(text); + break; + } + } + + return table.Count == 0; + }, resourceName, cancellationToken).ConfigureAwait(false); + } + catch (TaskCanceledException te) when (cancellationToken.IsCancellationRequested) + { + throw new TaskCanceledException($"Task was canceled before these messages were found: '{string.Join("', '", table)}'", te); + } + } + private static async Task WatchNotifications(DistributedApplication app, string? resourceName, Predicate predicate, TaskCompletionSource tcs, CancellationTokenSource cancellationTokenSource) { var resourceNotificationService = app.Services.GetRequiredService(); @@ -98,10 +131,12 @@ private static async Task WatchNotifications(DistributedApplication app, string? catch (OperationCanceledException) { // Expected if the application stops prematurely or the text was detected. + tcs.TrySetCanceled(); } catch (Exception ex) { logger.LogError(ex, "An error occurred while watching for resource notifications."); + tcs.TrySetException(ex); } } diff --git a/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj b/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj index 67930e243a9..90de102a099 100644 --- a/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj +++ b/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj @@ -42,8 +42,10 @@ + + diff --git a/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs b/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs new file mode 100644 index 00000000000..f662e152479 --- /dev/null +++ b/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Aspire.Hosting; +using Aspire.Hosting.Tests.Utils; +using SamplesIntegrationTests; +using SamplesIntegrationTests.Infrastructure; +using Xunit; +using Xunit.Abstractions; + +namespace Aspire.Playground.Tests; + +public class ProjectSpecificTests(ITestOutputHelper _testOutput) +{ + [Fact] + public async Task WithDockerfileTest() + { + var appHostPath = Directory.GetFiles(AppContext.BaseDirectory, "WithDockerfile.AppHost.dll").Single(); + var appHost = await DistributedApplicationTestFactory.CreateAsync(appHostPath, _testOutput); + await using var app = await appHost.BuildAsync(); + + await app.StartAsync(); + await app.WaitForResources().WaitAsync(TimeSpan.FromMinutes(2)); + + await app.WaitForTextAsync($"I'm Batman. - Batman") + .WaitAsync(TimeSpan.FromMinutes(3)); + + app.EnsureNoErrorsLogged(); + await app.StopAsync(); + } + + [Fact] + public async Task KafkaTest() + { + var appHostPath = Directory.GetFiles(AppContext.BaseDirectory, "KafkaBasic.AppHost.dll").Single(); + var appHost = await DistributedApplicationTestFactory.CreateAsync(appHostPath, _testOutput); + await using var app = await appHost.BuildAsync(); + + await app.StartAsync(); + await app.WaitForResources().WaitAsync(TimeSpan.FromMinutes(2)); + + await WaitForAllTextAsync(app, + [ + "Hello, World! 343", + "Received 1000 messages." + ], + timeoutSecs: 120); + + app.EnsureNoErrorsLogged(); + await app.StopAsync(); + } + + internal static Task WaitForAllTextAsync(DistributedApplication app, IEnumerable logTexts, string? resourceName = null, int timeoutSecs = -1) + { + CancellationTokenSource cts = new(); + if (timeoutSecs > 0) + { + cts.CancelAfter(TimeSpan.FromSeconds(timeoutSecs)); + } + + return app.WaitForAllTextAsync(logTexts, resourceName, cts.Token); + } +} diff --git a/tests/helix/send-to-helix-buildonhelixtests.targets b/tests/helix/send-to-helix-buildonhelixtests.targets index 1488f77ecb9..9029c46e586 100644 --- a/tests/helix/send-to-helix-buildonhelixtests.targets +++ b/tests/helix/send-to-helix-buildonhelixtests.targets @@ -14,6 +14,8 @@ + +