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
19 changes: 0 additions & 19 deletions tests/Aspire.EndToEnd.Tests/IntegrationServicesFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
using Xunit;
using Xunit.Abstractions;
using Aspire.TestProject;
Expand Down Expand Up @@ -100,8 +99,6 @@ public Task DumpComponentLogsAsync(TestResourceNames resource, ITestOutputHelper

string component = resource switch
{
TestResourceNames.cosmos or TestResourceNames.efcosmos => "cosmos",
TestResourceNames.eventhubs => "eventhubs",
TestResourceNames.postgres or TestResourceNames.efnpgsql => "postgres",
TestResourceNames.redis => "redis",
_ => throw new ArgumentException($"Unknown resource: {resource}")
Expand Down Expand Up @@ -133,8 +130,6 @@ private static TestResourceNames GetResourcesToSkip()
{
TestResourceNames resourcesToInclude = TestScenario switch
{
"cosmos" => TestResourceNames.cosmos | TestResourceNames.efcosmos,
"eventhubs" => TestResourceNames.eventhubs,
"basicservices" => TestResourceNames.redis
| TestResourceNames.postgres
| TestResourceNames.efnpgsql,
Expand All @@ -144,20 +139,6 @@ private static TestResourceNames GetResourcesToSkip()

TestResourceNames resourcesToSkip = TestResourceNames.All & ~resourcesToInclude;

// always skip cosmos on macos/arm64
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
{
resourcesToSkip |= TestResourceNames.cosmos;
}
if (string.IsNullOrEmpty(TestScenario))
{
// no scenario specified
if (BuildEnvironment.IsRunningOnCI)
{
resourcesToSkip |= TestResourceNames.cosmos;
}
}

// always skip the dashboard
resourcesToSkip |= TestResourceNames.dashboard;

Expand Down
25 changes: 0 additions & 25 deletions tests/Aspire.EndToEnd.Tests/IntegrationServicesTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
using Xunit;
using Xunit.Abstractions;
using Aspire.TestProject;
using Aspire.Workload.Tests;
using Microsoft.DotNet.XUnitExtensions;

namespace Aspire.EndToEnd.Tests;

Expand Down Expand Up @@ -45,29 +43,6 @@ public Task VerifyComponentWorks(TestResourceNames resourceName)
});

[Fact]
[Trait("scenario", "eventhubs")]
public Task VerifyAzureEventHubsComponentWorks()
=> VerifyComponentWorks(TestResourceNames.eventhubs);

[ActiveIssue("https://github.com/dotnet/aspire/issues/5820")]
[ConditionalTheory]
[Trait("scenario", "cosmos")]
[InlineData(TestResourceNames.cosmos)]
[InlineData(TestResourceNames.efcosmos)]
public Task VerifyCosmosComponentWorks(TestResourceNames resourceName)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
{
throw new SkipTestException($"Skipping 'cosmos' test because the emulator isn't supported on macOS ARM64.");
}

return VerifyComponentWorks(resourceName);
}

[Fact]
// Include all the scenarios here so this test gets run for all of them.
// https://github.com/dotnet/aspire/issues/5820
// [Trait("scenario", "cosmos")]
[Trait("scenario", "basicservices")]
public Task VerifyHealthyOnIntegrationServiceA()
=> RunTestAsync(async () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.OperationalInsights\Aspire.Hosting.Azure.OperationalInsights.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.ApplicationInsights\Aspire.Hosting.Azure.ApplicationInsights.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.AppConfiguration\Aspire.Hosting.Azure.AppConfiguration.csproj" />
<ProjectReference Include="..\..\src\Components\Aspire.Azure.Messaging.EventHubs\Aspire.Azure.Messaging.EventHubs.csproj" />
<ProjectReference Include="..\..\src\Components\Aspire.Azure.Storage.Blobs\Aspire.Azure.Storage.Blobs.csproj" />
<ProjectReference Include="..\..\src\Components\Aspire.Microsoft.Azure.Cosmos\Aspire.Microsoft.Azure.Cosmos.csproj" />
<ProjectReference Include="..\..\src\Components\Aspire.Microsoft.EntityFrameworkCore.Cosmos\Aspire.Microsoft.EntityFrameworkCore.Cosmos.csproj" />
<ProjectReference Include="..\Aspire.Hosting.Tests\Aspire.Hosting.Tests.csproj" />

<ProjectReference Include="..\..\src\Components\Aspire.Azure.Storage.Blobs\Aspire.Azure.Storage.Blobs.csproj" />

<Compile Include="$(RepoRoot)src\Aspire.Hosting.Azure.EventHubs\EventHubsEmulatorContainerImageTags.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Azure.Storage\AzureStorageEmulatorConnectionString.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Utils;
using Microsoft.Azure.Cosmos;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
Expand Down Expand Up @@ -59,7 +60,7 @@ public async Task VerifyWaitForOnCosmosDBEmulatorBlocksDependentResources()
await app.StopAsync();
}

[Fact(Skip = "Using CosmosDB emulator in integration tests leads to flaky tests")]
[Fact(Skip = "Using CosmosDB emulator in integration tests leads to flaky tests - https://github.com/dotnet/aspire/issues/5820")]
[RequiresDocker(Reason = "CosmosDB emulator is needed for this test")]
public async Task VerifyCosmosResource()
{
Expand Down Expand Up @@ -89,13 +90,9 @@ public async Task VerifyCosmosResource()
await app.StartAsync();

var hb = Host.CreateApplicationBuilder();

hb.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
{
[$"ConnectionStrings:{db.Resource.Name}"] = await db.Resource.ConnectionStringExpression.GetValueAsync(default)
});

hb.Configuration[$"ConnectionStrings:{db.Resource.Name}"] = await db.Resource.ConnectionStringExpression.GetValueAsync(default);
hb.AddAzureCosmosClient(db.Resource.Name);
hb.AddCosmosDbContext<EFCoreCosmosDbContext>(db.Resource.Name, databaseName);

using var host = hb.Build();

Expand All @@ -104,6 +101,7 @@ public async Task VerifyCosmosResource()
// This needs to be outside the pipeline because when the CosmosClient is disposed,
// there is an exception in the pipeline
using var cosmosClient = host.Services.GetRequiredService<CosmosClient>();
using var dbContext = host.Services.GetRequiredService<EFCoreCosmosDbContext>();

await pipeline.ExecuteAsync(async token =>
{
Expand All @@ -115,10 +113,15 @@ await pipeline.ExecuteAsync(async token =>

Assert.True(results.Count == 1);
Assert.True(results.First() == 1);

await dbContext.Database.EnsureCreatedAsync(token);
dbContext.AddRange([new Entry(), new Entry()]);
var count = await dbContext.SaveChangesAsync(token);
Assert.Equal(2, count);
}, cts.Token);
}

[Fact(Skip = "Using CosmosDB emulator in integration tests leads to flaky tests")]
[Fact(Skip = "Using CosmosDB emulator in integration tests leads to flaky tests - https://github.com/dotnet/aspire/issues/5820")]
[RequiresDocker]
public async Task WithDataVolumeShouldPersistStateBetweenUsages()
{
Expand Down Expand Up @@ -246,3 +249,13 @@ await pipeline.ExecuteAsync(async token =>
DockerUtils.AttemptDeleteDockerVolume(volumeName);
}
}

public class EFCoreCosmosDbContext(DbContextOptions<EFCoreCosmosDbContext> options) : DbContext(options)
{
public DbSet<Entry> Entries { get; set; }
}

public record Entry
{
public Guid Id { get; set; } = Guid.NewGuid();
}
49 changes: 44 additions & 5 deletions tests/Aspire.Hosting.Azure.Tests/AzureEventHubsExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// 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.Utils;
using Aspire.Hosting.Azure.EventHubs;
using Xunit;
using System.Text;
using Aspire.Components.Common.Tests;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Azure.EventHubs;
using Aspire.Hosting.Utils;
using Azure.Messaging.EventHubs;
using Azure.Messaging.EventHubs.Consumer;
using Azure.Messaging.EventHubs.Producer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Aspire.Components.Common.Tests;
using Microsoft.Extensions.Hosting;
using Xunit;
using Xunit.Abstractions;

namespace Aspire.Hosting.Azure.Tests;
Expand Down Expand Up @@ -56,6 +61,40 @@ public async Task VerifyWaitForOnEventHubsEmulatorBlocksDependentResources()
await app.StopAsync();
}

[Fact]
[RequiresDocker]
public async Task VerifyAzureEventHubsEmulatorResource()
{
using var builder = TestDistributedApplicationBuilder.Create().WithTestAndResourceLogging(testOutputHelper);
var eventHub = builder.AddAzureEventHubs("eventhubns")
.RunAsEmulator()
.AddEventHub("hub");

using var app = builder.Build();
await app.StartAsync();

var hb = Host.CreateApplicationBuilder();
hb.Configuration["ConnectionStrings:eventhubns"] = await eventHub.Resource.ConnectionStringExpression.GetValueAsync(CancellationToken.None);
hb.AddAzureEventHubProducerClient("eventhubns", settings => settings.EventHubName = "hub");
hb.AddAzureEventHubConsumerClient("eventhubns", settings => settings.EventHubName = "hub");

using var host = hb.Build();
await host.StartAsync();

var producerClient = host.Services.GetRequiredService<EventHubProducerClient>();
var consumerClient = host.Services.GetRequiredService<EventHubConsumerClient>();

// If no exception is thrown when awaited, the Event Hubs service has acknowledged
// receipt and assumed responsibility for delivery of the set of events to its partition.
await producerClient.SendAsync([new EventData(Encoding.UTF8.GetBytes("hello worlds"))]);

await foreach (var partitionEvent in consumerClient.ReadEventsAsync(new ReadEventOptions { MaximumWaitTime = TimeSpan.FromSeconds(5) }))
{
Assert.Equal("hello worlds", Encoding.UTF8.GetString(partitionEvent.Data.EventBody.ToArray()));
break;
}
}

[Fact]
public void AzureEventHubsUseEmulatorCallbackWithWithDataBindMountResultsInBindMountAnnotationWithDefaultPath()
{
Expand All @@ -79,7 +118,7 @@ public void AzureEventHubsUseEmulatorCallbackWithWithDataBindMountResultsInBindM
using var builder = TestDistributedApplicationBuilder.Create();
var eventHubs = builder.AddAzureEventHubs("eh").RunAsEmulator(configureContainer: builder =>
{
builder.WithDataBindMount("mydata");
builder.WithDataBindMount("mydata");
});

// Ignoring the annotation created for the custom Config.json file
Expand Down
4 changes: 1 addition & 3 deletions tests/Aspire.Hosting.Tests/DistributedApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,7 @@ public async Task KubernetesHasResourceNameForContainersAndExes()
var expectedContainerResources = new HashSet<string>()
{
"redis",
"postgres",
"cosmos",
"eventhubns"
"postgres"
};

await foreach (var resource in s.WatchAsync<Container>(cancellationToken: token))
Expand Down
21 changes: 1 addition & 20 deletions tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,7 @@ public void VerifyTestProgramFullManifest()
"HTTP_PORTS": "{integrationservicea.bindings.http.targetPort}",
"SKIP_RESOURCES": "None",
"ConnectionStrings__redis": "{redis.connectionString}",
"ConnectionStrings__postgresdb": "{postgresdb.connectionString}",
"ConnectionStrings__cosmos": "{cosmos.connectionString}",
"ConnectionStrings__eventhubns": "{eventhubns.connectionString}"
"ConnectionStrings__postgresdb": "{postgresdb.connectionString}"
},
"bindings": {
"http": {
Expand Down Expand Up @@ -471,23 +469,6 @@ public void VerifyTestProgramFullManifest()
"type": "value.v0",
"connectionString": "{postgres.connectionString};Database=postgresdb"
},
"cosmos": {
"type": "azure.bicep.v0",
"connectionString": "{cosmos.secretOutputs.connectionString}",
"path": "cosmos.module.bicep",
"params": {
"keyVaultName": ""
}
},
"eventhubns": {
"type": "azure.bicep.v0",
"connectionString": "{eventhubns.outputs.eventHubsEndpoint}",
"path": "eventhubns.module.bicep",
"params": {
"principalId": "",
"principalType": ""
}
},
"postgres-password": {
"type": "parameter.v0",
"value": "{postgres-password.inputs.value}",
Expand Down
37 changes: 0 additions & 37 deletions tests/cosmos.module.bicep

This file was deleted.

36 changes: 0 additions & 36 deletions tests/eventhubns.module.bicep

This file was deleted.

5 changes: 1 addition & 4 deletions tests/testproject/Common/TestResourceNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ namespace Aspire.TestProject;
public enum TestResourceNames
{
None = 0,
cosmos = 1 << 0,
dashboard = 1 << 1,
postgres = 1 << 7,
redis = 1 << 9,
efnpgsql = 1 << 11,
eventhubs = 1 << 13,
efcosmos = 1 << 17,
All = cosmos | dashboard | postgres | redis | efnpgsql | eventhubs | efcosmos
All = dashboard | postgres | redis | efnpgsql
}

public static class TestResourceNamesExtensions
Expand Down
Loading