[WIP] Migrates Azure storage tests to use Testcontainers#9921
[WIP] Migrates Azure storage tests to use Testcontainers#9921Meir017 wants to merge 12 commits intodotnet:mainfrom
Conversation
…Storage - Add AzuriteContainer static singleton that lazily starts an Azurite Testcontainer (or reuses an already-running instance on default ports). - Replace StorageEmulator usage in TestUtils.CheckForAzureStorage() with AzuriteContainer.EnsureStartedAsync(). - Fall back DataConnectionString to AzuriteContainer.ConnectionString when no explicit config is provided. - Add Testcontainers package reference to TestExtensions project.
Azurite is now managed in-process by Testcontainers via AzuriteContainer. The Event Hubs job retains the Azurite service container because the Event Hubs emulator Docker container depends on it for blob/metadata storage, but its ORLEANSDATACONNECTIONSTRING is removed since the test process will detect the already-running Azurite on default ports.
…r setup Replace manual ContainerBuilder configuration with AzuriteBuilder from the Testcontainers.Azurite NuGet package. This provides built-in image selection, port bindings, wait strategies, and a GetConnectionString() method. Also enables WithInMemoryPersistence() for faster test execution.
Resolves naming conflict with Testcontainers.Azurite.AzuriteContainer.
Remove the AAD authentication support from test infrastructure since all Azure Storage tests now use the Azurite emulator via Testcontainers. - Remove UseAadAuthentication, TokenCredential, TableEndpoint, DataBlobUri, DataQueueUri, and EventHubFullyQualifiedNamespace from TestDefaultConfiguration - Simplify CheckForAzureStorage to only start the Azurite container - Simplify CheckForEventHub to only check connection string - Remove AAD branches from AzureStorageOperationOptionsExtensions, EventHubConfigurationExtensions, CosmosOptionsExtensions, JournalingAzureStorageTestConfiguration, and other test files - Remove unused Azure.Identity package from TestExtensions.csproj
…tring Remove the redundant DataConnectionString property from TestDefaultConfiguration and use AzuriteContainerManager.ConnectionString directly in all test files.
There was a problem hiding this comment.
Pull request overview
This is a work-in-progress PR that migrates Azure Storage testing infrastructure from GitHub Actions services to Testcontainers, specifically focusing on Azurite. The change is part of a broader initiative (issue #9708) to simplify the testing infrastructure and make tests easier to run locally.
Changes:
- Introduces
AzuriteContainerManagerto manage a singleton Azurite container using Testcontainers - Removes Azure AD authentication support from test configuration (TestDefaultConfiguration)
- Updates all Azure Storage test configurations to use the new container manager instead of environment variables
- Removes Azurite service definition from GitHub Actions workflow for Azure Storage tests
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/TestInfrastructure/TestExtensions/AzuriteContainerManager.cs | New singleton manager for Azurite Testcontainer with lazy initialization |
| test/TestInfrastructure/TestExtensions/TestDefaultConfiguration.cs | Removed Azure AD authentication properties and connection string configurations |
| test/TestInfrastructure/TestExtensions/TestUtils.cs | Updated CheckForAzureStorage to use AzuriteContainerManager |
| test/TestInfrastructure/TestExtensions/TestExtensions.csproj | Replaced Azure.Identity dependency with Testcontainers.Azurite |
| test/TesterInternal/GeoClusterTests/BasicLogTestGrainTests.cs | Migrated to use AzuriteContainerManager connection string |
| test/Tester/Forwarding/ShutdownSiloTests.cs | Migrated to use AzuriteContainerManager connection string |
| test/Extensions/TesterAzureUtils/Streaming/TestAzureTableStorageStreamFailureHandler.cs | Migrated to use AzuriteContainerManager connection string |
| test/Extensions/TesterAzureUtils/Streaming/AQStreamingTests.cs | Migrated to use AzuriteContainerManager connection string |
| test/Extensions/TesterAzureUtils/StorageEmulatorUtilities.cs | Updated to check AzuriteContainerManager connection string |
| test/Extensions/TesterAzureUtils/AzureStorageOperationOptionsExtensions.cs | Removed Azure AD auth logic and migrated all extension methods to use AzuriteContainerManager |
| test/Extensions/Tester.Cosmos/CosmosOptionsExtensions.cs | Simplified to remove Azure AD authentication support |
| test/Extensions/ServiceBus.Tests/EventHubConfigurationExtensions.cs | Simplified to remove Azure AD authentication support |
| test/Orleans.Journaling.Tests/JournalingAzureStorageTestConfiguration.cs | Updated to use AzuriteContainerManager connection string |
| test/Benchmarks/Transactions/TransactionBenchmark.cs | Migrated to use AzuriteContainerManager connection string |
| test/Benchmarks/GrainStorage/GrainStorageBenchmark.cs | Migrated to use AzuriteContainerManager connection string (with bug in AdoNet configurator) |
| NuGet.Config | Commented out Azure DevOps package feeds (should not be in this PR) |
| src/Directory.Build.props | Commented out Microsoft.DotNet.GenAPI.Task (should not be in this PR) |
| Directory.Packages.props | Added Testcontainers.Azurite package version |
| .github/workflows/ci.yml | Removed Azurite service and connection string from Azure Storage test job |
test/TestInfrastructure/TestExtensions/AzuriteContainerManager.cs
Outdated
Show resolved
Hide resolved
test/TestInfrastructure/TestExtensions/AzuriteContainerManager.cs
Outdated
Show resolved
Hide resolved
test/Orleans.Journaling.Tests/JournalingAzureStorageTestConfiguration.cs
Show resolved
Hide resolved
…tils Use a Lazy<bool> for thread-safe singleton initialization instead of manual lock and Task caching. Add synchronous EnsureStarted() with SkipException, matching the ConsulTestUtils pattern.
…v var Tests using StandaloneSiloHandle spawn silos in separate processes. Each process was starting its own Azurite container, so silos registered gateways in a different container than the one the client queried. Propagate the connection string via ORLEANS_AZURITE_CONNECTION_STRING environment variable so child processes reuse the same container.
|
getting errors seems random 😔 |
| hostBuilder.AddAzureTableGrainStorageAsDefault(options => | ||
| { | ||
| options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString); | ||
| options.TableServiceClient = new(AzuriteContainerManager.ConnectionString); |
There was a problem hiding this comment.
When we run these tests in internal Azure DevOps, we target real storage backends and TestDefaultConfiguration loads real creds. It looks like this would hard-code the tests to always use Azurite
There was a problem hiding this comment.
@ReubenBond oh, so we want to keep using these dedicated real storage accounts? for some reason I assumed we want to use the testcontainers everywhere...
There was a problem hiding this comment.
@Meir017 We want Testcontainers in GitHub (since we don't want to expose secrets, etc) but we need the option to test against real services, too, to improve confidence since sometimes there are gaps (Cosmos DB is a good example of gaps between emulator and real service).
|
@Meir017 the Consul Testcontainers commit is causing failures in our internal Azure DevOps, I suppose we aren't allowed to access docker.io from there. I'm trying to see if we can fix that (#9933). We might need to disable Testcontainers tests in AzDO. |
I believe they have some strict rate limits on dockerhub. So creating a custom container registry and copying specific images could work (like the aspire repo does) |
related to #9708
Microsoft Reviewers: Open in CodeFlow