Skip to content

fix(EventHubs): Ignore runtime property to support reuse#1644

Merged
HofmeisterAn merged 1 commit intotestcontainers:developfrom
franciscosamuel:bugfix/eventhubs-reuse-resource
Mar 2, 2026
Merged

fix(EventHubs): Ignore runtime property to support reuse#1644
HofmeisterAn merged 1 commit intotestcontainers:developfrom
franciscosamuel:bugfix/eventhubs-reuse-resource

Conversation

@franciscosamuel
Copy link
Copy Markdown
Contributor

@franciscosamuel franciscosamuel commented Mar 2, 2026

What does this PR do?

Makes the configuration hash of EventHubsContainer stable by removing the AzeriteContainer from the hashed configuration.

Why is it important?

The AzeriteContainer contains runtime information about the database container such as the start time which changes everytime, resulting in an always changing configuration hash, which breaks the Resource Reuse feature for EventHubs containers.

Related issues

How to test this PR

Since this concerns cross-execution tests, an automated test would become quite convoluted. The easiest way to test this is to temporarily modify the configurations on EventHubsCustomAzuriteConfiguration and DatabaseFixture to both use .WithReuse(true) and running the test twice. The first execution should create the containers and the second should reuse them.

Follow-ups

Issue #1642 can be closed after this and #1643 are merged

Summary by CodeRabbit

  • Chores
    • Updated JSON serialization configuration for EventHubsConfiguration to exclude the AzuriteContainer property from serialization output.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 2, 2026

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 4bdf8f3
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/69a5c3cd853589000898f7d5
😎 Deploy Preview https://deploy-preview-1644--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 project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 2, 2026

Walkthrough

Adds a [JsonIgnore] attribute to the AzuriteContainer property in EventHubsConfiguration and includes the corresponding namespace using statement. This prevents the property from being serialized when comparing container signatures for resource reuse functionality.

Changes

Cohort / File(s) Summary
EventHubs Configuration
src/Testcontainers.EventHubs/EventHubsConfiguration.cs
Added [JsonIgnore] attribute to the AzuriteContainer property to exclude it from JSON serialization during resource reuse signature comparison.
Namespace Imports
src/Testcontainers.EventHubs/Usings.cs
Added global using directive for System.Text.Json.Serialization to support the JsonIgnore attribute.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested labels

bug

Suggested reviewers

  • HofmeisterAn

Poem

🐰 A container tries to reuse, but Azure won't let it through,
Runtime whispers secrets that signature can't construe,
With [JsonIgnore] as our wand, we hide what shouldn't show,
And resource reuse blooms brightly—let the EventHubs flow! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The PR description includes all mandatory sections (What does this PR do, Why is it important) and recommended sections (Related issues, How to test), with clear explanations of the changes and their purpose.
Linked Issues check ✅ Passed The code changes directly address the root cause identified in issue #1642: adding [JsonIgnore] to exclude runtime-dependent properties from configuration hashing to enable stable resource reuse.
Out of Scope Changes check ✅ Passed Both changes (adding [JsonIgnore] to AzuriteContainer and adding the required System.Text.Json.Serialization using) are directly scoped to fixing the resource reuse issue; no extraneous modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly identifies the main change: adding [JsonIgnore] to exclude AzuriteContainer from serialization to enable resource reuse for EventHubs containers, which directly addresses the PR's core objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Testcontainers.EventHubs/EventHubsConfiguration.cs`:
- Around line 64-65: Add a regression test in the EventHubs test suite that
constructs two EventHubsConfiguration instances which differ only in their
AzuriteContainer runtime instance (leave ServiceConfiguration identical) and
asserts their reuse signature/hash (the same mechanism used elsewhere to
determine container reuse) is equal, then mutate ServiceConfiguration on one
instance and assert the reuse signature/hash changes; reference the
EventHubsConfiguration type and its AzuriteContainer and ServiceConfiguration
properties in the test to ensure AzuriteContainer is ignored in the signature
while ServiceConfiguration affects it.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8482b5 and 4bdf8f3.

📒 Files selected for processing (2)
  • src/Testcontainers.EventHubs/EventHubsConfiguration.cs
  • src/Testcontainers.EventHubs/Usings.cs

Comment on lines +64 to 65
[JsonIgnore]
public AzuriteContainer AzuriteContainer { get; }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

git ls-files | head -20

Repository: testcontainers/testcontainers-dotnet

Length of output: 613


🏁 Script executed:

fd -t f "EventHubsConfiguration" --max-results 5

Repository: testcontainers/testcontainers-dotnet

Length of output: 134


🏁 Script executed:

fd -t d "test|Test" | head -10

Repository: testcontainers/testcontainers-dotnet

Length of output: 440


🏁 Script executed:

cat -n "src/Testcontainers.EventHubs/EventHubsConfiguration.cs" | head -80

Repository: testcontainers/testcontainers-dotnet

Length of output: 3634


🏁 Script executed:

fd -t d "EventHubs" | grep -i test

Repository: testcontainers/testcontainers-dotnet

Length of output: 147


🏁 Script executed:

rg -l "EventHubsConfiguration" --type=cs | grep -i test

Repository: testcontainers/testcontainers-dotnet

Length of output: 300


🏁 Script executed:

find tests/Testcontainers.EventHubs.Tests -type f -name "*.cs" | head -20

Repository: testcontainers/testcontainers-dotnet

Length of output: 257


🏁 Script executed:

rg "reuse|signature|hash|WithReuse|ResourceHash" tests/Testcontainers.EventHubs.Tests --type=cs -l

Repository: testcontainers/testcontainers-dotnet

Length of output: 62


🏁 Script executed:

rg "JsonIgnore|json|JSON" tests/Testcontainers.EventHubs.Tests --type=cs -l

Repository: testcontainers/testcontainers-dotnet

Length of output: 62


🏁 Script executed:

rg -l "reuse|signature|hash|WithReuse|ResourceHash" src/Testcontainers.EventHubs --type=cs

Repository: testcontainers/testcontainers-dotnet

Length of output: 62


🏁 Script executed:

cat tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs

Repository: testcontainers/testcontainers-dotnet

Length of output: 4556


🏁 Script executed:

rg "reuse|signature|hash|WithReuse|ResourceHash" src --type=cs | head -30

Repository: testcontainers/testcontainers-dotnet

Length of output: 4560


🏁 Script executed:

rg "JsonIgnore" src --type=cs | head -20

Repository: testcontainers/testcontainers-dotnet

Length of output: 1935


🏁 Script executed:

rg -l "reuse|hash.*signature|ResourceHash" tests --type=cs | head -10

Repository: testcontainers/testcontainers-dotnet

Length of output: 388


🏁 Script executed:

rg "WithReuse|ResourceReuse" tests --type=cs -A 5 | head -40

Repository: testcontainers/testcontainers-dotnet

Length of output: 3910


🏁 Script executed:

find src -name "*ResourceConfiguration*" -o -name "*ReuseHash*" | xargs cat

Repository: testcontainers/testcontainers-dotnet

Length of output: 5873


🏁 Script executed:

cat tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs | head -100

Repository: testcontainers/testcontainers-dotnet

Length of output: 4148


🏁 Script executed:

rg "EventHubsConfiguration|GetReuseHash" tests --type=cs -B 2 -A 5

Repository: testcontainers/testcontainers-dotnet

Length of output: 4252


🏁 Script executed:

find tests -name "*Hash*" -o -name "*Signature*" | head -10

Repository: testcontainers/testcontainers-dotnet

Length of output: 62


Add a regression test to lock this hashing behavior for EventHubs configurations.

This fix is correct—excluding AzuriteContainer from the reuse hash via [JsonIgnore] aligns with the framework pattern and prevents runtime container state from affecting the signature. However, EventHubs currently lacks specific test coverage verifying that the reuse signature remains stable when only Azurite runtime state changes, while still changing when actual EventHubs config inputs (ServiceConfiguration) change. Add a test case in the EventHubs test suite to assert this behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Testcontainers.EventHubs/EventHubsConfiguration.cs` around lines 64 - 65,
Add a regression test in the EventHubs test suite that constructs two
EventHubsConfiguration instances which differ only in their AzuriteContainer
runtime instance (leave ServiceConfiguration identical) and asserts their reuse
signature/hash (the same mechanism used elsewhere to determine container reuse)
is equal, then mutate ServiceConfiguration on one instance and assert the reuse
signature/hash changes; reference the EventHubsConfiguration type and its
AzuriteContainer and ServiceConfiguration properties in the test to ensure
AzuriteContainer is ignored in the signature while ServiceConfiguration affects
it.

@HofmeisterAn HofmeisterAn changed the title fix(EventHubs): Resource Reuse fix(EventHubs): Ignore runtime property to support reuse Mar 2, 2026
@HofmeisterAn HofmeisterAn added the bug Something isn't working label Mar 2, 2026
@HofmeisterAn HofmeisterAn merged commit 7cd1c8d into testcontainers:develop Mar 2, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Resource Reuse doesn't work for ServiceBusContainer

2 participants