Skip to content

fix(toxiproxy): add Toxiproxy container module - #1105

Open
JonnasFigueiredo wants to merge 1 commit into
testcontainers:mainfrom
JonnasFigueiredo:feature/toxiproxy-container
Open

fix(toxiproxy): add Toxiproxy container module#1105
JonnasFigueiredo wants to merge 1 commit into
testcontainers:mainfrom
JonnasFigueiredo:feature/toxiproxy-container

Conversation

@JonnasFigueiredo

Copy link
Copy Markdown

New Container

Fixes #1104

Adds a ToxiproxyContainer (testcontainers.community.toxiproxy) that wraps Toxiproxy for simulating adverse network conditions — latency, bandwidth limits, connection drops and more — in integration tests. Toxiproxy modules already exist for testcontainers Java, Go and .NET; this brings the same to Python.

What it does

  • ToxiproxyContainer exposes the HTTP control API (8474) and a range of proxy ports, and waits on the control API before it's ready.
  • create_proxy(name, upstream) routes traffic to an upstream (e.g. "nginx:80" of a container that shares a network) and returns a ToxiproxyProxy whose host/proxy_port you connect through.
  • ToxiproxyProxy.add_toxic(...) injects toxics via the control API.
  • No extra runtime dependencies — the control API is called over urllib.

Usage

with Network() as network:
    nginx = NginxContainer("nginx:alpine").with_network(network).with_network_aliases("nginx")
    toxiproxy = ToxiproxyContainer().with_network(network)
    with nginx, toxiproxy:
        proxy = toxiproxy.create_proxy("nginx", "nginx:80")
        proxy.add_toxic("latency", {"latency": 1000})  # 1s downstream latency

The included integration test starts nginx behind Toxiproxy, verifies traffic flows through the proxy, then injects a latency toxic and asserts the response is delayed.

PR Checklist

  • Your PR title follows the Conventional Commits syntax — uses fix(toxiproxy): as recommended for community modules.
  • Your PR allows maintainers to edit your branch.
  • The new container is implemented under src/testcontainers/community/toxiproxy/
    • Namespacing follows testcontainers.community.toxiproxy.*.
    • Tests under tests/community/toxiproxy/.
    • docs/community/toxiproxy.rst with the .. autoclass and .. title directives.
    • Feature implemented in __init__.py with corresponding tests. Docs page + example added under docs/modules/ and the nav entry in mkdocs.yml.
  • Added in pyproject.toml under project.optional-dependencies as toxiproxy = [] (no extra dependencies).
  • Branch is up-to-date.

Adds a ToxiproxyContainer under testcontainers.community.toxiproxy for
simulating adverse network conditions (latency, bandwidth limits,
connection drops, ...) in integration tests, mirroring the Toxiproxy
modules already available for testcontainers Java, Go and .NET.

- ToxiproxyContainer exposes the HTTP control API and a range of proxy
  ports and provides create_proxy() to route traffic to an upstream.
- ToxiproxyProxy.add_toxic() injects toxics via the control API.
- No extra runtime dependencies (the control API is called over urllib).
- Adds an integration test (proxying + latency toxic), a docs page and
  example, and the community extra in pyproject.
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.

New Container: Toxiproxy

1 participant