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

Add CosmosDB trigger test for Functions #7285

Closed
wants to merge 2 commits into from
Closed
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 @@ -4,8 +4,8 @@
using Azure.Messaging.EventHubs.Producer;
#if !SKIP_UNSTABLE_EMULATORS
using Azure.Messaging.ServiceBus;
using Microsoft.Azure.Cosmos;
#endif
using Microsoft.Azure.Cosmos;
using Azure.Storage.Blobs;
using Azure.Storage.Queues;
using Newtonsoft.Json;
Expand All @@ -17,9 +17,9 @@
builder.AddAzureQueueClient("queue");
builder.AddAzureBlobClient("blob");
builder.AddAzureEventHubProducerClient("eventhubs", static settings => settings.EventHubName = "myhub");
builder.AddAzureCosmosClient("cosmosdb");
#if !SKIP_UNSTABLE_EMULATORS
builder.AddAzureServiceBusClient("messaging");
builder.AddAzureCosmosClient("cosmosdb");
#endif

var app = builder.Build();
Expand Down Expand Up @@ -67,6 +67,7 @@ static string RandomString(int length)
await sender.SendMessageAsync(message, cancellationToken);
return Results.Ok("Message sent to Azure Service Bus.");
});
#endif

app.MapGet("/publish/cosmosdb", async (CosmosClient cosmosClient) =>
{
Expand All @@ -78,7 +79,6 @@ static string RandomString(int length)

return Results.Ok("Document created in Azure Cosmos DB.");
});
#endif

app.MapGet("/", async (HttpClient client) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.EventHubs" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.Storage" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.ServiceBus" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.CosmosDb" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.CosmosDB" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.AppHost" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
var eventHubs = builder.AddAzureEventHubs("eventhubs").RunAsEmulator().WithHub("myhub");
#if !SKIP_UNSTABLE_EMULATORS
var serviceBus = builder.AddAzureServiceBus("messaging").RunAsEmulator().WithQueue("myqueue");
#endif
var cosmosDb = builder.AddAzureCosmosDB("cosmosdb")
.RunAsEmulator()
.WithDatabase("mydatabase", (database)
=> database.Containers.AddRange([new("mycontainer", "/id")]));
#endif

var funcApp = builder.AddAzureFunctionsProject<Projects.AzureFunctionsEndToEnd_Functions>("funcapp")
.WithExternalHttpEndpoints()
.WithReference(eventHubs).WaitFor(eventHubs)
#if !SKIP_UNSTABLE_EMULATORS
.WithReference(serviceBus).WaitFor(serviceBus)
.WithReference(cosmosDb).WaitFor(cosmosDb)
#endif
.WithReference(cosmosDb).WaitFor(cosmosDb)
.WithReference(blob)
.WithReference(queue);

builder.AddProject<Projects.AzureFunctionsEndToEnd_ApiService>("apiservice")
.WithReference(eventHubs).WaitFor(eventHubs)
#if !SKIP_UNSTABLE_EMULATORS
.WithReference(serviceBus).WaitFor(serviceBus)
.WithReference(cosmosDb).WaitFor(cosmosDb)
#endif
.WithReference(cosmosDb).WaitFor(cosmosDb)
.WithReference(queue)
.WithReference(blob)
.WithReference(funcApp);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#if !SKIP_UNSTABLE_EMULATORS
using System.Reflection.Metadata;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
Expand All @@ -17,4 +16,3 @@ public void Run([CosmosDBTrigger(
logger.LogInformation("C# cosmosdb trigger function processed: {Count} messages", input.Count);
}
}
#endif
9 changes: 9 additions & 0 deletions tests/Aspire.Playground.Tests/ProjectSpecificTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ await WaitForAllTextAsync(app,
timeoutSecs: 160);
#endif

// Assert that CosmosDB triggers work correctly
await apiServiceClient.GetAsync("/publish/cosmosdb");
await WaitForAllTextAsync(app,
[
"Executed 'Functions.MyCosmosDbTrigger'"
],
resourceName: "funcapp",
timeoutSecs: 160);

// 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
// worker extension has been built and before the host has launched.
Expand Down
Loading