Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Azure ServiceBus emulator functional tests #7067

Merged
merged 1 commit into from
Jan 10, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();

Expand Down Expand Up @@ -52,13 +56,15 @@ 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");
var message = new ServiceBusMessage(Encoding.UTF8.GetBytes(RandomString(length)));
await sender.SendMessageAsync(message, cancellationToken);
return Results.Ok("Message sent to Azure Service Bus.");
});
#endif

app.MapGet("/", async (HttpClient client) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Projects.AzureFunctionsEndToEnd_Functions>("funcapp")
.WithExternalHttpEndpoints()
.WithReference(eventHubs).WaitFor(eventHubs)
#if !SKIP_UNSTABLE_EMULATORS
.WithReference(serviceBus).WaitFor(serviceBus)
#endif
.WithReference(blob)
.WithReference(queue);

builder.AddProject<Projects.AzureFunctionsEndToEnd_ApiService>("apiservice")
.WithReference(eventHubs).WaitFor(eventHubs)
#if !SKIP_UNSTABLE_EMULATORS
.WithReference(serviceBus).WaitFor(serviceBus)
#endif
.WithReference(queue)
.WithReference(blob)
.WithReference(funcApp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +17,9 @@ namespace AzureFunctionsEndToEnd.Functions;

public class MyHttpTrigger(
ILogger<MyHttpTrigger> logger,
#if !SKIP_UNSTABLE_EMULATORS
ServiceBusClient serviceBusClient,
#endif
EventHubProducerClient eventHubProducerClient,
QueueServiceClient queueServiceClient,
BlobServiceClient blobServiceClient)
Expand All @@ -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}");
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -17,3 +18,4 @@ public void Run([ServiceBusTrigger("myqueue", Connection = "messaging")] Service
logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions playground/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<!-- Skip dashboard when building outside the repo, like on helix. Or when
building on CI -->
<SkipDashboardProjectReference Condition="'$(SkipDashboardProjectReference)' == '' and ('$(RepoRoot)' == '' or '$(ContinuousIntegrationBuild)' == 'true')">true</SkipDashboardProjectReference>
<!-- Skip emulators that don't start consistently when running in CI. -->
<SkipUnstableEmulators Condition="'$(SkipUnstableEmulators)' == '' and ('$(RepoRoot)' == '' or '$(ContinuousIntegrationBuild)' == 'true' or '$(CODESPACES)' == 'true')">true</SkipUnstableEmulators>
</PropertyGroup>

<ItemGroup Condition="'$(IsAspireHost)' == 'true' and '$(SkipDashboardProjectReference)' != 'true'">
Expand All @@ -24,5 +26,6 @@

<PropertyGroup >
<DefineConstants Condition="'$(SkipDashboardProjectReference)' == 'true'">SKIP_DASHBOARD_REFERENCE;$(DefineConstants)</DefineConstants>
<DefineConstants Condition="'$(SkipUnstableEmulators)' == 'true'">SKIP_UNSTABLE_EMULATORS;$(DefineConstants)</DefineConstants>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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()
{
Expand Down
6 changes: 6 additions & 0 deletions tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
<PlaygroundSourceDir>$(MSBuildThisFileDirectory)..\..\playground\</PlaygroundSourceDir>
<TestsSharedDir>$(MSBuildThisFileDirectory)..\Shared\</TestsSharedDir>
<RunSettingsFilePath>$(MSBuildThisFileDirectory).runsettings</RunSettingsFilePath>
<!-- Skip emulators that don't start consistently when running in CI. -->
Copy link
Member

Choose a reason for hiding this comment

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

NIT: I know you did it on the facts, but might be good to also add the link to the issue tracking removing this in here too. Also not block on this, if you agree we can add it in your next set of changes.

<SkipUnstableEmulators Condition="'$(SkipUnstableEmulators)' == '' and ('$(RepoRoot)' == '' or '$(ContinuousIntegrationBuild)' == 'true' or '$(CODESPACES)' == 'true')">true</SkipUnstableEmulators>

<!-- on helix this will be available in the source dir -->
<XunitRunnerJson Condition="'$(RepoRoot)' == ''">xunit.runner.json</XunitRunnerJson>
</PropertyGroup>

<PropertyGroup Condition="'$(SkipUnstableEmulators)' == 'true'">
Copy link
Member

Choose a reason for hiding this comment

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

NIT: Can this just be done in the parent's Directory.Build.props so it applies to both playground and tests and that way we don't have to change multiple places later?

Feel free to not block on this one, but just something to consider.

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that we already had this code in the repo.

One reason to not put it in the root of the repo is so it doesn't affect other projects - like stuff under src.

<DefineConstants>SKIP_UNSTABLE_EMULATORS;$(DefineConstants)</DefineConstants>
</PropertyGroup>

<ItemGroup>
<!-- on helix, the file will be in the source directory, so it will get
picked up by msbuild by default -->
Expand Down
2 changes: 2 additions & 0 deletions tests/Aspire.Playground.Tests/ProjectSpecificTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
Loading