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

feat(servicebus): Add support to use a custom MsSqlContainer instance with Service Bus emulator #1335

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

lgcmotta
Copy link

@lgcmotta lgcmotta commented Jan 11, 2025

What does this PR do?

This PR exposes an overload of WithMsSqlContainer, enabling users to attach an existing MsSqlContainer instance to the Azure Service Bus emulator. Previously, ServiceBusContainer automatically spun up its own SQL Server container, leading to unnecessary duplication when users were already testing with Azure Service Bus and SQL Server (see #1323).

Why is it important?

This enhancement addresses the resource usage issues described in #1323. By allowing a single MsSqlContainer to be shared, the overhead of launching a separate SQL Server container to use the Azure Service Bus emulator is eliminated. This can be especially beneficial in CI/CD scenarios or other environments where minimizing resource consumption and reducing test execution time is a priority.

Related issues

How to test this PR

  • A new test has been added that demonstrates attaching a custom MsSqlContainer to ServiceBusContainer.
  • Ensure both containers (ServiceBusContainer and MsSqlContainer) are on the same network.
  • Use a non-default SQL Server image, for example: mcr.microsoft.com/azure-sql-edge:latest.
  • Verify that only the containers you intend to run are launched (Azure SQL Edge for SQL Server, and the Azure Service Bus emulator), and that mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04 (the default in MsSqlBuilder) is not spun up.

Follow-ups

None at this time. Inline summary documentation is included in the new overload.

Copy link

netlify bot commented Jan 11, 2025

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit fee7110
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-dotnet/deploys/67840c91963a720008207387
😎 Deploy Preview https://deploy-preview-1335--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +45 to +51
var typeAssemblyName = containerType.Assembly.GetName().Name;

if (!string.IsNullOrWhiteSpace(testAssemblyName) && !string.IsNullOrWhiteSpace(typeAssemblyName) && !testAssemblyName.Contains(typeAssemblyName))
{
continue;
}

Copy link
Author

Choose a reason for hiding this comment

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

When adding a new test that creates an MS SQL instance, the MsSqlContainer type was exported under Testcontainers.ServiceBus.Tests.dll. This caused the test to detect IContainer implementations that aren’t part of the Service Bus assembly. Ideally, verifying that MsSqlContainer implements IDatabaseContainer should happen in its theory case (Testcontainers.MsSql.Tests), rather than in the Testcontainers.ServiceBus.Tests.dll theory case.

I’d appreciate any suggestions on how to handle these cross-assembly references without causing false positives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: Allow Azure Service Bus to use an existent instance of MsSqlContainer
1 participant