chaotic

module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT

README

chaotic

test codecov Go Reference Go Report Card Release

In-process Go chaos library. Wrap your integration boundaries — http.RoundTripper, net/http middleware, database/sql driver, gRPC interceptors — and inject latency, errors, panics, and connection drops on demand. When no rules are configured the wrappers are near-zero-cost passthroughs; chaotic is safe to leave linked everywhere.

Status

v1, test-only mode. Production-mode hooks (HTTP admin endpoint, file-watcher rule source, observers) are forward-compatible additions planned for v2.

Install

go get github.com/ag4r/chaotic
go get github.com/ag4r/chaotic/adapter/grpc   # only if you need gRPC chaos

Quick example

package main

import (
	"io"
	"net/http"
	"time"

	chaoshttp "github.com/ag4r/chaotic/adapter/http"
	"github.com/ag4r/chaotic/chaostest"
	"github.com/ag4r/chaotic/engine"
	"github.com/ag4r/chaotic/fault"
)

func TestRetriesOnTransientError(t *testing.T) {
	eng := chaostest.New(t)
	eng.AddRule(engine.NewRule(
		engine.MatchKind(engine.OpHTTPClient),
		engine.MatchName("/users/*"),
		engine.Times(2),
		engine.WithFaults(fault.Latency(200*time.Millisecond), fault.Error(io.ErrUnexpectedEOF)),
	).Named("transient-failure"))

	client := &http.Client{Transport: chaoshttp.WrapTransport(http.DefaultTransport, eng)}
	// ... call code under test that uses `client` and is supposed to retry ...

	chaostest.AssertHits(t, eng, "transient-failure", 2)
	chaostest.AssertEventsExhausted(t, eng)
}

Modules

This repo contains two Go modules:

  • github.com/ag4r/chaotic — engine, faults, and the HTTP / HTTP server / SQL adapters. Stdlib only.
  • github.com/ag4r/chaotic/adapter/grpc — gRPC interceptors. Depends on google.golang.org/grpc.

A go.work file at the repo root makes the workspace resolve both modules during development. Run tests with:

go test ./...                 # main module
go -C adapter/grpc test ./... # gRPC submodule

Directories

Path Synopsis
adapter
http
Package http wraps an http.RoundTripper so outbound client calls are subject to chaos.
Package http wraps an http.RoundTripper so outbound client calls are subject to chaos.
httpsrv
Package httpsrv provides net/http middleware that subjects inbound requests to chaos.
Package httpsrv provides net/http middleware that subjects inbound requests to chaos.
sql
Package sql wraps a database/sql driver so calls are subject to chaos.
Package sql wraps a database/sql driver so calls are subject to chaos.
Package chaostest provides testing.TB integration helpers for chaotic.
Package chaostest provides testing.TB integration helpers for chaotic.
quick
Package quick provides opinionated one-line shortcuts for the most common chaos test setups.
Package quick provides opinionated one-line shortcuts for the most common chaos test setups.
Package engine holds the rules and decision logic that adapters consult on every wrapped operation.
Package engine holds the rules and decision logic that adapters consult on every wrapped operation.
Package fault defines the fault primitives that rules execute when they fire.
Package fault defines the fault primitives that rules execute when they fire.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL