From eaa241c59242d1c47e7b2ed908f58f0de03901e7 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Thu, 30 Jan 2025 09:51:13 -0600 Subject: [PATCH] Enable ServiceBus Emulator tests in CI --- .../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 -- .../AzureServiceBusExtensionsTests.cs | 4 ++-- tests/Aspire.Playground.Tests/ProjectSpecificTests.cs | 2 -- 7 files changed, 8 insertions(+), 20 deletions(-) diff --git a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.ApiService/Program.cs b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.ApiService/Program.cs index 456092124a2..865b940da07 100644 --- a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.ApiService/Program.cs +++ b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.ApiService/Program.cs @@ -2,8 +2,8 @@ using System.Text; using Azure.Messaging.EventHubs; using Azure.Messaging.EventHubs.Producer; -#if !SKIP_UNSTABLE_EMULATORS using Azure.Messaging.ServiceBus; +#if !SKIP_UNSTABLE_EMULATORS using Microsoft.Azure.Cosmos; #endif using Azure.Storage.Blobs; @@ -17,8 +17,8 @@ builder.AddAzureQueueClient("queue"); builder.AddAzureBlobClient("blob"); builder.AddAzureEventHubProducerClient("eventhubs", static settings => settings.EventHubName = "myhub"); -#if !SKIP_UNSTABLE_EMULATORS builder.AddAzureServiceBusClient("messaging"); +#if !SKIP_UNSTABLE_EMULATORS builder.AddAzureCosmosClient("cosmosdb"); #endif @@ -59,7 +59,6 @@ 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"); @@ -68,6 +67,7 @@ static string RandomString(int length) return Results.Ok("Message sent to Azure Service Bus."); }); +#if !SKIP_UNSTABLE_EMULATORS app.MapGet("/publish/cosmosdb", async (CosmosClient cosmosClient) => { var db = cosmosClient.GetDatabase("mydatabase"); diff --git a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/Program.cs b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/Program.cs index d1035f24c81..abafcde669b 100644 --- a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/Program.cs +++ b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/Program.cs @@ -4,8 +4,8 @@ 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"); +#if !SKIP_UNSTABLE_EMULATORS var cosmosDb = builder.AddAzureCosmosDB("cosmosdb") .RunAsEmulator() .WithDatabase("mydatabase", (database) @@ -15,8 +15,8 @@ var funcApp = builder.AddAzureFunctionsProject("funcapp") .WithExternalHttpEndpoints() .WithReference(eventHubs).WaitFor(eventHubs) -#if !SKIP_UNSTABLE_EMULATORS .WithReference(serviceBus).WaitFor(serviceBus) +#if !SKIP_UNSTABLE_EMULATORS .WithReference(cosmosDb).WaitFor(cosmosDb) #endif .WithReference(blob) @@ -24,8 +24,8 @@ builder.AddProject("apiservice") .WithReference(eventHubs).WaitFor(eventHubs) -#if !SKIP_UNSTABLE_EMULATORS .WithReference(serviceBus).WaitFor(serviceBus) +#if !SKIP_UNSTABLE_EMULATORS .WithReference(cosmosDb).WaitFor(cosmosDb) #endif .WithReference(queue) diff --git a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyHttpTrigger.cs b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyHttpTrigger.cs index dda47d7e73c..b6ec904fa1d 100644 --- a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyHttpTrigger.cs +++ b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyHttpTrigger.cs @@ -4,9 +4,7 @@ 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; @@ -17,9 +15,7 @@ namespace AzureFunctionsEndToEnd.Functions; public class MyHttpTrigger( ILogger logger, -#if !SKIP_UNSTABLE_EMULATORS ServiceBusClient serviceBusClient, -#endif EventHubProducerClient eventHubProducerClient, QueueServiceClient queueServiceClient, BlobServiceClient blobServiceClient) @@ -29,9 +25,7 @@ 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 773a5fef71e..6ef5d818a52 100644 --- a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyServiceBusTrigger.cs +++ b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyServiceBusTrigger.cs @@ -1,4 +1,3 @@ -#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. @@ -18,4 +17,3 @@ 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 b82415ef881..e2342c0d3a1 100644 --- a/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/Program.cs +++ b/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/Program.cs @@ -7,9 +7,7 @@ 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/tests/Aspire.Hosting.Azure.Tests/AzureServiceBusExtensionsTests.cs b/tests/Aspire.Hosting.Azure.Tests/AzureServiceBusExtensionsTests.cs index 4a0a014c9fd..5006d9d16ce 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(Skip = "Azure ServiceBus emulator is not reliable in CI - https://github.com/dotnet/aspire/issues/7066")] + [Fact] [RequiresDocker] public async Task VerifyWaitForOnServiceBusEmulatorBlocksDependentResources() { @@ -224,7 +224,7 @@ public async Task VerifyWaitForOnServiceBusEmulatorBlocksDependentResources() await app.StopAsync(); } - [Fact(Skip = "Azure ServiceBus emulator is not reliable in CI - https://github.com/dotnet/aspire/issues/7066")] + [Fact] [RequiresDocker] public async Task VerifyAzureServiceBusEmulatorResource() { diff --git a/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs b/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs index b5ea77f5e27..371932d1136 100644 --- a/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs +++ b/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs @@ -114,7 +114,6 @@ 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, @@ -123,7 +122,6 @@ 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