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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions playground/kafka/Consumer/ConsumerWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion playground/withdockerfile/WithDockerfile.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

builder.AddDockerfile("mycontainer", "qots")
.WithBuildArg("GO_VERSION", goVersion)
.WithBuildSecret("SECRET_ASENV", secret);
.WithBuildSecret("SECRET_ASENV", secret)
.WithEnvironment("DOCKER_BUILDKIT", "1");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this here or in the MSBuild file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set it here to have it close to where it is needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have it in both places?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is set for tests running on the build machine (note to self: can be dropped now), and for basictests on helix.


#if !SKIP_DASHBOARD_REFERENCE
// This project is only added in playground projects to support development/debugging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,39 @@ public static Task WaitForTextAsync(this DistributedApplication app, Predicate<s
return tcs.Task;
}

/// <summary>
/// Waits for all the specified texts to be logged.
/// </summary>
/// <param name="app">The <see cref="DistributedApplication" /> instance to watch.</param>
/// <param name="logTexts">Any text to wait for.</param>
/// <param name="resourceName">An optional resource name to filter the logs for.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
public static async Task WaitForAllTextAsync(this DistributedApplication app, IEnumerable<string> 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<string> predicate, TaskCompletionSource tcs, CancellationTokenSource cancellationTokenSource)
{
var resourceNotificationService = app.Services.GetRequiredService<ResourceNotificationService>();
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
<ProjectReference Include="$(PlaygroundSourceDir)Qdrant/Qdrant.AppHost/Qdrant.AppHost.csproj" />
<ProjectReference Include="$(PlaygroundSourceDir)SqlServerEndToEnd/SqlServerEndToEnd.AppHost/SqlServerEndToEnd.AppHost.csproj" />
<ProjectReference Include="$(PlaygroundSourceDir)TestShop/TestShop.AppHost/TestShop.AppHost.csproj" />
<ProjectReference Include="$(PlaygroundSourceDir)kafka/KafkaBasic.AppHost/KafkaBasic.AppHost.csproj" />
<ProjectReference Include="$(PlaygroundSourceDir)keycloak/Keycloak.AppHost/Keycloak.AppHost.csproj" />
<ProjectReference Include="$(PlaygroundSourceDir)milvus/MilvusPlayground.AppHost/MilvusPlayground.AppHost.csproj" />
<ProjectReference Include="$(PlaygroundSourceDir)withdockerfile/WithDockerfile.AppHost/WithDockerfile.AppHost.csproj" />

<!-- Issue: https://github.com/dotnet/aspire/issues/5274 -->
<!-- Only `dotnet run` startup checked -->
Expand Down
63 changes: 63 additions & 0 deletions tests/Aspire.Playground.Tests/ProjectSpecificTests.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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);
}
}
2 changes: 2 additions & 0 deletions tests/helix/send-to-helix-buildonhelixtests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<ItemGroup>
<HelixPreCommand Include="$(_EnvVarSetKeyword) SkipDashboardProjectReference=true" />
<HelixPreCommand Include="$(_EnvVarSetKeyword) TestsRunningOutsideOfRepo=true" />
<!-- required for tests that build docker images, like Aspire.Playground.Tests -->
<HelixPreCommand Include="$(_EnvVarSetKeyword) DOCKER_BUILDKIT=1" />

<HelixPreCommand Condition="'$(OS)' == 'Windows_NT'" Include="set NUGET_PACKAGES=%HELIX_WORKITEM_ROOT%\nuget-cache\" />
<HelixPreCommand Condition="'$(OS)' != 'Windows_NT'" Include="export NUGET_PACKAGES=$HELIX_WORKITEM_ROOT/nuget-cache/" />
Expand Down