{"id":13564505,"url":"https://github.com/Jcambass/toxiproxy_ex","last_synced_at":"2025-04-03T21:30:59.549Z","repository":{"id":49059281,"uuid":"304367934","full_name":"Jcambass/toxiproxy_ex","owner":"Jcambass","description":"ToxiproxyEx is an Elixir API client for the resilience testing tool Toxiproxy.","archived":false,"fork":false,"pushed_at":"2024-03-06T15:35:51.000Z","size":81,"stargazers_count":54,"open_issues_count":5,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T16:21:51.395Z","etag":null,"topics":["elixir","resilience","toxiproxy"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jcambass.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-15T15:22:47.000Z","updated_at":"2025-02-17T15:15:49.000Z","dependencies_parsed_at":"2023-11-16T14:43:16.146Z","dependency_job_id":"9540a0fd-0f00-485a-b4db-17a45955f665","html_url":"https://github.com/Jcambass/toxiproxy_ex","commit_stats":{"total_commits":11,"total_committers":3,"mean_commits":"3.6666666666666665","dds":"0.36363636363636365","last_synced_commit":"4cd5f6a01fee631bcf93217844ab101800c281ab"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jcambass%2Ftoxiproxy_ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jcambass%2Ftoxiproxy_ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jcambass%2Ftoxiproxy_ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jcambass%2Ftoxiproxy_ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jcambass","download_url":"https://codeload.github.com/Jcambass/toxiproxy_ex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247083046,"owners_count":20880764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","resilience","toxiproxy"],"created_at":"2024-08-01T13:01:32.329Z","updated_at":"2025-04-03T21:30:56.277Z","avatar_url":"https://github.com/Jcambass.png","language":"Elixir","funding_links":[],"categories":["Testing"],"sub_categories":[],"readme":"# ToxiproxyEx\n\n[![github.com](https://github.com/Jcambass/toxiproxy_ex/workflows/.github/workflows/main.yml/badge.svg)](https://github.com/Jcambass/toxiproxy_ex/actions)\n[![hex.pm](https://img.shields.io/hexpm/v/toxiproxy_ex.svg)](https://hex.pm/packages/toxiproxy_ex)\n[![hexdocs.pm](https://img.shields.io/badge/api-docs-lightgreen.svg)](https://hexdocs.pm/toxiproxy_ex/api-reference.html)\n[![hex.pm](https://img.shields.io/hexpm/dt/toxiproxy_ex.svg)](https://hex.pm/packages/toxiproxy_ex)\n[![hex.pm](https://img.shields.io/hexpm/l/toxiproxy_ex.svg)](https://hex.pm/packages/toxiproxy_ex)\n[![github.com](https://img.shields.io/github/last-commit/Jcambass/toxiproxy_ex.svg)](https://github.com/Jcambass/toxiproxy_ex/commits/main)\n\n\u003c!-- MDOC !--\u003e\n\nToxiproxyEx is an Elixir API client for the resilience testing tool Toxiproxy.\n\n[Toxiproxy](https://github.com/shopify/toxiproxy) is a proxy to simulate network\nand system conditions. The Elixir API aims to make it simple to write tests that\nensure your application behaves appropriately under harsh conditions. Before you\ncan use the Elixir library, you need to read the [Usage section of the Toxiproxy\nREADME](https://github.com/shopify/toxiproxy#usage).\n\n## Usage\n\nBy default the Elixir client communicates with the Toxiproxy daemon via HTTP on `http://127.0.0.1:8474`, but you can point to any host via your application configuration:\n```elixir\nconfig :toxiproxy_ex, host: \"http://toxiproxy.local:8844\"\n```\n\nFor example, to simulate 1000ms latency on a database server you can use the\n`latency` toxic with the `latency` argument (see the Toxiproxy project for a\nlist of all toxics):\n\n```elixir\nToxiproxyEx.get!(:mysql_master)\n|\u003e ToxiproxyEx.toxic(:latency, latency: 1000)\n|\u003e ToxiproxyEx.apply!(fn -\u003e\n  Repo.all(Shop) # this took at least 1s\nend)\n```\n\nYou can also take an endpoint down for the duration of a function at the TCP level:\n\n```elixir\nToxiproxyEx.get!(:mysql_master)\n|\u003e ToxiproxyEx.down!(fn -\u003e\n  Repo.all(Shop) # this'll raise\nend)\n```\n\nIf you want to simulate all your Redis instances being down:\n\n```elixir\nToxiproxyEx.grep!(~r/redis/)\n|\u003e ToxiproxyEx.down!(fn -\u003e\n  # any redis call will fail\nend)\n```\n\nIf you want to simulate that your cache server is slow at incoming network\n(upstream), but fast at outgoing (downstream), you can apply a toxic to just the\nupstream:\n\n```elixir\nToxiproxyEx.get!(:cache)\n|\u003e ToxiproxyEx.upstream(:latency, latency: 1000)\n|\u003e ToxiproxyEx.apply!(fn -\u003e\n  Cache.get(:omg) # will take at least a second\nend)\n```\n\nBy default the toxic is applied to the downstream connection, you can be\nexplicit and compose them:\n\n```elixir\nToxiproxyEx.grep!(~r/redis/)\n|\u003e ToxiproxyEx.upstream(:slow_close, delay: 100)\n|\u003e ToxiproxyEx.downstream(:latency, jitter: 300)\n|\u003e ToxiproxyEx.apply!(fn -\u003e\n  # all redises are now slow at responding and closing\nend)\n```\n\nSee the [Toxiproxy README](https://github.com/shopify/toxiproxy#Toxics) for a\nlist of toxics.\n\n## Populate\n\nTo populate Toxiproxy pass the proxy configurations to `ToxiproxyEx.populate!`:\n\n```elixir\nToxiproxyEx.populate!([\n  %{\n    name: \"mysql_master\",\n    listen: \"localhost:21212\",\n    upstream: \"localhost:3306\",\n  },\n  %{\n    name: \"mysql_read_only\",\n    listen: \"localhost:21213\",\n    upstream: \"localhost:3306\",\n  }\n])\n```\n\nThis will create the proxies passed, or replace the proxies if they already exist in Toxiproxy.\nIt's recommended to do this as early in your application startup process as possible, see the\n[Toxiproxy README](https://github.com/shopify/toxiproxy#usage). If you have many\nproxies, we recommend storing the Toxiproxy configs in a configuration file and\ndeserializing it into `ToxiproxyEx.populate!/1`.\n\n## Error Handling\n\nThis library made the choice to use exceptions on the public API methods to signal errors.\n\nThis was chosen since this is a library meant to be used in testing code only, where you want test cases to fail if your set assumptions are not met. In this sense setting assumptions that will not be met (toxiproxy-server is not running, passing invalid configurations) is considered to be a developer error and should be fixed rather than handled in code.\n\n**Server Errors**\n\nIf any API interaction with toxiproxy fails, a `ServerError` will be raised.\n\n**Client Errors**\n\nIf you miss-configure toxiproxy via the elixir API, an `ArgumentError` will be raised.\n\n\u003c!-- MDOC !--\u003e\n\n## Installation\n\nThe package can be installed\nby adding `toxiproxy_ex` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:toxiproxy_ex, \"~\u003e 2.0.0\", only: :test}\n  ]\nend\n```\n\n## Running tests\n\nClone the repo and fetch its dependencies:\n\n    $ git clone https://github.com/jcambass/toxiproxy_ex.git\n    $ cd toxiproxy_ex\n    $ mix deps.get\n\nMake sure that you have [Toxiproxy](https://github.com/Shopify/toxiproxy) installed and start it:\n\n    $ toxiproxy-server\n\nRun tests:\n\n    $ mix test\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJcambass%2Ftoxiproxy_ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJcambass%2Ftoxiproxy_ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJcambass%2Ftoxiproxy_ex/lists"}