From 74c835c88463207dae99398d4449105d05287b09 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 10 Jan 2025 15:52:55 -0600 Subject: [PATCH] Disable Azure ServiceBus emulator functional tests The emulator isn't reliable / consistent in CI. Disabling for now. See #7066 --- .../AzureFunctionsEndToEnd.ApiService/Program.cs | 6 ++++++ .../AzureFunctionsEndToEnd.AppHost/Program.cs | 6 ++++++ .../AzureFunctionsEndToEnd.Functions/MyHttpTrigger.cs | 6 ++++++ .../AzureFunctionsEndToEnd.Functions/MyServiceBusTrigger.cs | 2 ++ .../AzureFunctionsEndToEnd.Functions/Program.cs | 2 ++ playground/Directory.Build.targets | 3 +++ .../AzureServiceBusExtensionsTests.cs | 4 ++-- .../Aspire.Playground.Tests/Aspire.Playground.Tests.csproj | 6 ++++++ tests/Aspire.Playground.Tests/ProjectSpecificTests.cs | 2 ++ 9 files changed, 35 insertions(+), 2 deletions(-) diff --git a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.ApiService/Program.cs b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.ApiService/Program.cs index aac0cdc1c7..f04cc3b41b 100644 --- a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.ApiService/Program.cs +++ b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.ApiService/Program.cs @@ -2,7 +2,9 @@ using System.Text; using Azure.Messaging.EventHubs; using Azure.Messaging.EventHubs.Producer; +#if !SKIP_UNSTABLE_EMULATORS using Azure.Messaging.ServiceBus; +#endif using Azure.Storage.Blobs; using Azure.Storage.Queues; @@ -13,7 +15,9 @@ builder.AddAzureQueueClient("queue"); builder.AddAzureBlobClient("blob"); builder.AddAzureEventHubProducerClient("eventhubs", static settings => settings.EventHubName = "myhub"); +#if !SKIP_UNSTABLE_EMULATORS builder.AddAzureServiceBusClient("messaging"); +#endif var app = builder.Build(); @@ -52,6 +56,7 @@ static string RandomString(int length) return Results.Ok("Message sent to Azure EventHubs."); }); +#if !SKIP_UNSTABLE_EMULATORS app.MapGet("/publish/asb", async (ServiceBusClient client, CancellationToken cancellationToken, int length = 20) => { var sender = client.CreateSender("myqueue"); @@ -59,6 +64,7 @@ static string RandomString(int length) await sender.SendMessageAsync(message, cancellationToken); return Results.Ok("Message sent to Azure Service Bus."); }); +#endif app.MapGet("/", async (HttpClient client) => { diff --git a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/Program.cs b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/Program.cs index 1884d0ef99..d9ed4670d7 100644 --- a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/Program.cs +++ b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/Program.cs @@ -4,18 +4,24 @@ var queue = storage.AddQueues("queue"); var blob = storage.AddBlobs("blob"); var eventHubs = builder.AddAzureEventHubs("eventhubs").RunAsEmulator().WithHub("myhub"); +#if !SKIP_UNSTABLE_EMULATORS var serviceBus = builder.AddAzureServiceBus("messaging").RunAsEmulator().WithQueue("myqueue"); +#endif var funcApp = builder.AddAzureFunctionsProject("funcapp") .WithExternalHttpEndpoints() .WithReference(eventHubs).WaitFor(eventHubs) +#if !SKIP_UNSTABLE_EMULATORS .WithReference(serviceBus).WaitFor(serviceBus) +#endif .WithReference(blob) .WithReference(queue); builder.AddProject("apiservice") .WithReference(eventHubs).WaitFor(eventHubs) +#if !SKIP_UNSTABLE_EMULATORS .WithReference(serviceBus).WaitFor(serviceBus) +#endif .WithReference(queue) .WithReference(blob) .WithReference(funcApp); diff --git a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyHttpTrigger.cs b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyHttpTrigger.cs index b6ec904fa1..dda47d7e73 100644 --- a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyHttpTrigger.cs +++ b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyHttpTrigger.cs @@ -4,7 +4,9 @@ using System.Globalization; using System.Text; using Azure.Messaging.EventHubs.Producer; +#if !SKIP_UNSTABLE_EMULATORS using Azure.Messaging.ServiceBus; +#endif using Azure.Storage.Blobs; using Azure.Storage.Queues; using Microsoft.AspNetCore.Http; @@ -15,7 +17,9 @@ namespace AzureFunctionsEndToEnd.Functions; public class MyHttpTrigger( ILogger logger, +#if !SKIP_UNSTABLE_EMULATORS ServiceBusClient serviceBusClient, +#endif EventHubProducerClient eventHubProducerClient, QueueServiceClient queueServiceClient, BlobServiceClient blobServiceClient) @@ -25,7 +29,9 @@ public IResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] Ht { logger.LogInformation("C# HTTP trigger function processed a request."); var stringBuilder = new StringBuilder(); +#if !SKIP_UNSTABLE_EMULATORS stringBuilder.AppendLine(CultureInfo.InvariantCulture, $"Aspire-injected ServiceBusClient namespace: {serviceBusClient.FullyQualifiedNamespace}"); +#endif stringBuilder.AppendLine(CultureInfo.InvariantCulture, $"Aspire-injected EventHubProducerClient namespace: {eventHubProducerClient.FullyQualifiedNamespace}"); stringBuilder.AppendLine(CultureInfo.InvariantCulture, $"Aspire-injected QueueServiceClient URI: {queueServiceClient.Uri}"); stringBuilder.AppendLine(CultureInfo.InvariantCulture, $"Aspire-injected BlobServiceClient URI: {blobServiceClient.Uri}"); diff --git a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyServiceBusTrigger.cs b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyServiceBusTrigger.cs index 6ef5d818a5..773a5fef71 100644 --- a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyServiceBusTrigger.cs +++ b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyServiceBusTrigger.cs @@ -1,3 +1,4 @@ +#if !SKIP_UNSTABLE_EMULATORS // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. @@ -17,3 +18,4 @@ public void Run([ServiceBusTrigger("myqueue", Connection = "messaging")] Service logger.LogInformation("Message Content-Type: {contentType}", message.ContentType); } } +#endif diff --git a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/Program.cs b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/Program.cs index e2342c0d3a..b82415ef88 100644 --- a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/Program.cs +++ b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/Program.cs @@ -7,7 +7,9 @@ builder.AddAzureQueueClient("queue"); builder.AddAzureBlobClient("blob"); builder.AddAzureEventHubProducerClient("eventhubs", static settings => settings.EventHubName = "myhub"); +#if !SKIP_UNSTABLE_EMULATORS builder.AddAzureServiceBusClient("messaging"); +#endif builder.ConfigureFunctionsWebApplication(); diff --git a/playground/Directory.Build.targets b/playground/Directory.Build.targets index c659cc94fb..7bdf6ce9f3 100644 --- a/playground/Directory.Build.targets +++ b/playground/Directory.Build.targets @@ -5,6 +5,8 @@ true + + true @@ -24,5 +26,6 @@ SKIP_DASHBOARD_REFERENCE;$(DefineConstants) + SKIP_UNSTABLE_EMULATORS;$(DefineConstants) diff --git a/tests/Aspire.Hosting.Azure.Tests/AzureServiceBusExtensionsTests.cs b/tests/Aspire.Hosting.Azure.Tests/AzureServiceBusExtensionsTests.cs index 5006d9d16c..4a0a014c9f 100644 --- a/tests/Aspire.Hosting.Azure.Tests/AzureServiceBusExtensionsTests.cs +++ b/tests/Aspire.Hosting.Azure.Tests/AzureServiceBusExtensionsTests.cs @@ -182,7 +182,7 @@ param principalId string Assert.Equal(expectedBicep, manifest.BicepText); } - [Fact] + [Fact(Skip = "Azure ServiceBus emulator is not reliable in CI - https://github.com/dotnet/aspire/issues/7066")] [RequiresDocker] public async Task VerifyWaitForOnServiceBusEmulatorBlocksDependentResources() { @@ -224,7 +224,7 @@ public async Task VerifyWaitForOnServiceBusEmulatorBlocksDependentResources() await app.StopAsync(); } - [Fact] + [Fact(Skip = "Azure ServiceBus emulator is not reliable in CI - https://github.com/dotnet/aspire/issues/7066")] [RequiresDocker] public async Task VerifyAzureServiceBusEmulatorResource() { diff --git a/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj b/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj index fa3258d22d..a2f009c483 100644 --- a/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj +++ b/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj @@ -17,11 +17,17 @@ $(MSBuildThisFileDirectory)..\..\playground\ $(MSBuildThisFileDirectory)..\Shared\ $(MSBuildThisFileDirectory).runsettings + + true xunit.runner.json + + SKIP_UNSTABLE_EMULATORS;$(DefineConstants) + + diff --git a/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs b/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs index 371932d113..b5ea77f5e2 100644 --- a/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs +++ b/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs @@ -114,6 +114,7 @@ await WaitForAllTextAsync(app, resourceName: "funcapp", timeoutSecs: 160); +#if !SKIP_UNSTABLE_EMULATORS // https://github.com/dotnet/aspire/issues/7066 // Assert that ServiceBus triggers work correctly await apiServiceClient.GetAsync("/publish/asb"); await WaitForAllTextAsync(app, @@ -122,6 +123,7 @@ await WaitForAllTextAsync(app, ], resourceName: "funcapp", timeoutSecs: 160); +#endif // TODO: The following line is commented out because the test fails due to an erroneous log in the Functions App // resource that happens after the Functions host has been built. The error log shows up after the Functions