testcontainers-dotnet icon indicating copy to clipboard operation
testcontainers-dotnet copied to clipboard

Adds Toxiproxy module and tests

Open iltertaha opened this issue 6 months ago β€’ 1 comments

What does this PR do?

Adds a new Testcontainers.Toxiproxy module that enables integration testing with Shopify's Toxiproxy. It provides a ToxiproxyContainer and a ToxiproxyBuilder to simulate various network conditions (latency, timeout, bandwidth limit, etc.) within containerized test environments.

This module uses the Toxiproxy.Net client library to interact with the Toxiproxy HTTP API.

Included tests cover basic proxy creation, toxic addition, and runtime behavior of network faults like latency and timeouts.

Why is it important?

There is currently no native Toxiproxy module in testcontainers-dotnet. Toxiproxy is a powerful tool for simulating real-world network issues such as slow connections, disconnections, or dropped packets.

How to test this PR.

dotnet test tests/Testcontainers.Toxiproxy.Tests

iltertaha avatar May 25 '25 18:05 iltertaha

Deploy Preview for testcontainers-dotnet ready!

Name Link
Latest commit a8e742ebbef4071011c8bf10389430d452aee89f
Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/690f3e6d65e97300089cb879
Deploy Preview https://deploy-preview-1454--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.

netlify[bot] avatar May 25 '25 18:05 netlify[bot]

Summary by CodeRabbit

Release Notes

  • New Features

    • Toxiproxy container support is now available, enabling network condition simulation in test environments.
  • Documentation

    • Added comprehensive guide covering Toxiproxy setup, proxy configuration, and network chaos application in .NET tests.

Walkthrough

Adds a new Testcontainers.Toxiproxy module (projects, builder/configuration/container types), documentation and mkdocs entry, solution and package updates, a new integration test project with latency-toxic tests and CI config, plus a small GrafanaContainer cleanup.

Changes

Cohort / File(s) Summary
Package & Solution
Directory.Packages.props, Testcontainers.sln
Add Toxiproxy.Net package version and register Testcontainers.Toxiproxy and Testcontainers.Toxiproxy.Tests in solution with GUIDs and configuration mappings.
Documentation
docs/modules/index.md, docs/modules/toxiproxy.md, mkdocs.yml
Add Toxiproxy module entry to modules index, add toxiproxy module documentation page, and update mkdocs navigation.
Module Project Files
src/Testcontainers.Toxiproxy/Testcontainers.Toxiproxy.csproj, src/Testcontainers.Toxiproxy/.editorconfig, src/Testcontainers.Toxiproxy/Usings.cs
New multi-target project (net8.0/net9.0/netstandard2.0/2.1) with editorconfig and global usings.
Module Implementation
src/Testcontainers.Toxiproxy/ToxiproxyBuilder.cs, src/Testcontainers.Toxiproxy/ToxiproxyConfiguration.cs, src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs
Add ToxiproxyBuilder (Init: image, control port, proxied ports, wait strategy; Clone/Merge/Build), ToxiproxyConfiguration (constructors/copy semantics), and ToxiproxyContainer (constructor).
Tests Project
tests/Testcontainers.Toxiproxy.Tests/Testcontainers.Toxiproxy.Tests.csproj, tests/Testcontainers.Toxiproxy.Tests/ToxiproxyContainerTest.cs, tests/Testcontainers.Toxiproxy.Tests/Usings.cs, tests/Testcontainers.Toxiproxy.Tests/.editorconfig, tests/Testcontainers.Toxiproxy.Tests/.runs-on
Add test project targeting net9.0 with test dependencies, global usings, editorconfig, CI runner, and an integration test measuring latency toxic behavior against Redis.
Minor refactor
src/Testcontainers.Grafana/GrafanaContainer.cs
Remove private _configuration field and its assignment from GrafanaContainer; no public API signature changes.
Test csproj comments
tests/Testcontainers.Grafana.Tests/Testcontainers.Grafana.Tests.csproj
Reposition comment markers around PackageReferences block (comments moved inside ItemGroup) without changing package references.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Dev as Developer
    participant Builder as ToxiproxyBuilder
    participant Container as ToxiproxyContainer
    participant Docker as Docker Engine
    participant Client as Toxiproxy.Net Client

    Dev->>Builder: new ToxiproxyBuilder()
    Builder->>Builder: Init() β€” set image, control port, proxied ports, wait strategy
    Dev->>Builder: Configure proxies (name, listen, upstream)
    Dev->>Builder: Build()
    Builder->>Container: Create(configuration)
    Dev->>Container: StartAsync()
    Container->>Docker: Start container
    Docker-->>Container: Running
    Container->>Client: Connect to control port, create proxies
    Client-->>Container: Proxies ready
    Dev->>Container: Apply toxic / Measure via mapped proxied port

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

  • Pay attention to:
    • Clone/Merge semantics and immutability in ToxiproxyBuilder and ToxiproxyConfiguration.
    • Init() port-binding loop, proxied port range and off-by-one details, and wait strategy endpoint (/version).
    • Integration test timing, network assumptions, and assertion ranges in ToxiproxyContainerTest.

Suggested reviewers

  • hamidjahad

Poem

πŸ‡ I hopped a container, set ports with delight,
Launched proxies and toxics to tinker at night.
Latency was measured, assertions took flight,
Docs and tests snug, CI humming bright.
Happy hops β€” network chaos now polite. πŸŽ‰

Pre-merge checks and finishing touches

βœ… Passed checks (3 passed)
Check name Status Explanation
Description check βœ… Passed The description includes all mandatory sections (What, Why) and recommended sections (How to test) from the template. It provides clear explanations of changes, rationale, and testing instructions, though it lacks explicit issue linking.
Docstring Coverage βœ… Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Title check βœ… Passed The PR title 'feat: Adds Toxiproxy module' accurately reflects the main changeβ€”it introduces a new Toxiproxy module to the Testcontainers.Net library. The title is concise, clear, and specific about the primary contribution.
✨ Finishing touches
  • [ ] πŸ“ Generate docstrings
πŸ§ͺ 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.

coderabbitai[bot] avatar Nov 08 '25 09:11 coderabbitai[bot]