Packages
snakepit
0.6.6
0.13.0
0.12.0
0.11.1
0.11.0
0.10.1
0.10.0
0.9.1
0.9.0
0.8.9
0.8.8
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.11
0.6.10
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.2
0.1.1
0.1.0
High-performance pooler and session manager for external language integrations. Supports Python, Node.js, Ruby, and more with gRPC streaming, session management, and production-ready process cleanup.
Current section
Files
Jump to
Current section
Files
README_TESTING.md
# Snakepit Testing Guide
This guide covers the testing approach for the Snakepit project, including test organization, running tests, and understanding test output.
## Test Overview
Snakepit contains comprehensive test coverage for:
- Protocol foundation (gRPC infrastructure)
- Core variable system with SessionStore
- Type system and serialization
- Bridge server implementation
- Worker lifecycle hardening (port persistence, channel reuse, ETS/DETS protections, logging redaction)
- Python integration
## Running Tests
### Basic Test Execution
```bash
# Run all tests
mix test
# Run tests with specific tags
mix test --exclude performance # Default: excludes performance tests
mix test --only performance # Run only performance tests
# Run specific test files
mix test test/snakepit/bridge/session_store_test.exs
mix test test/snakepit/streaming_regression_test.exs # gRPC streaming regression
mix test test/unit/grpc/grpc_worker_ephemeral_port_test.exs # Worker port persistence
mix test test/snakepit/grpc/bridge_server_test.exs # Channel reuse & parameter validation
mix test test/unit/pool/process_registry_security_test.exs # DETS/ETS access control
mix test test/unit/logger/redaction_test.exs # Log redaction summaries
# Run Python bridge tests (auto-activates .venv, regenerates protos, sets PYTHONPATH)
./test_python.sh
./test_python.sh -k streaming # Any args are forwarded to pytest
```
### Reliability Regression Targets (v0.6.6)
- `test/unit/grpc/grpc_worker_ephemeral_port_test.exs` – verifies workers persist negotiated ports and survive pool shutdown races.
- `test/snakepit/grpc/bridge_server_test.exs` – asserts BridgeServer reuses worker channels and surfaces invalid parameter errors.
- `test/unit/pool/process_registry_security_test.exs` – prevents direct DETS writes and confirms registry APIs enforce visibility.
- `test/unit/logger/redaction_test.exs` – exercises the redaction summaries that keep secrets out of logs.
- `test/unit/bridge/session_store_test.exs` – covers per-session and global quotas plus safe reuse of existing program slots.
### Test Modes
The test suite runs in different modes based on tags:
- **Default**: Unit and integration tests (excludes `:performance` tag)
- **Performance**: Benchmarks and latency tests (use `--only performance`)
## Understanding Test Output
### Expected Warnings
Some tests intentionally trigger warnings to verify error handling. These are **expected and normal**:
1. **gRPC Server Shutdown Warning**
```
⏰ gRPC server PID XXXXX did not exit gracefully within 500ms. Forcing SIGKILL.
```
This occurs during test cleanup when the gRPC server is forcefully terminated. It's expected behavior.
2. **Server Configuration**
All gRPC server configuration warnings have been resolved in the current implementation.
### Test Statistics
A typical successful test run shows:
```
Finished in 1.9 seconds (1.1s async, 0.7s sync)
182 tests, 0 failures
```
## Test Organization
```
test/
├── unit/
│ ├── bridge/ # SessionStore quotas, ToolRegistry validation
│ ├── config/ # Mix config normalization helpers
│ ├── grpc/ # Worker port persistence, channel reuse, telemetry
│ ├── logger/ # Redaction utilities
│ ├── mix/ # Diagnose tasks and shell fallbacks
│ ├── pool/ # Supervisor lifecycle, registry hardening
│ └── worker_profile/ # Profile-specific control logic
├── snakepit/
│ ├── bridge/ # End-to-end bridge flows
│ ├── grpc/ # BridgeServer + heartbeat integration
│ ├── integration/ # Cross-language happy-paths
│ ├── pool/ # Session affinity + multipool integration
│ ├── telemetry/ # Metrics + tracing plumbing
│ └── worker_profile/ # Profile behaviour under real pools
├── performance/ # Optional perf benchmarks (:performance tag)
├── support/ # Shared helpers and fixtures
└── test_helper.exs # Global test configuration
```
## Key Test Categories
### 1. Protocol Tests
Tests the gRPC protocol implementation including:
- Service definitions
- Message serialization
- RPC handlers
### 2. Type System Tests
Validates the type system including:
- Type validation and constraints
- Serialization/deserialization
- Special value handling (infinity, NaN)
### 3. SessionStore Tests
Tests the core state management:
- Session lifecycle
- Variable CRUD operations
- Batch operations
- TTL and cleanup
### 4. Integration Tests
End-to-end tests covering:
- Python-Elixir communication
- Full request/response cycles
- Error propagation
## Writing Tests
### Test Patterns
1. **Use descriptive test names**
```elixir
test "handles special float values correctly" do
# Test implementation
end
```
2. **Group related tests with describe blocks**
```elixir
describe "batch operations" do
test "get_variables returns all found variables" do
# Test implementation
end
end
```
3. **Capture expected logs**
```elixir
{result, logs} = with_log(fn ->
# Code that generates expected warnings
end)
assert logs =~ "Expected warning message"
```
### Performance Tests
Performance tests are tagged and excluded by default:
```elixir
@tag :performance
test "handles 1000 concurrent requests" do
# Performance test implementation
end
```
## Continuous Integration
The test suite is designed to run in CI environments:
- All tests must pass before merging
- Performance tests are run separately
- Test coverage is monitored
## Troubleshooting
### Common Issues
1. **Port Already in Use**
- The gRPC server uses port 50051
- Ensure no other services are using this port
2. **Python Dependencies**
- Some integration tests require the Python bridge packages
- Create a virtualenv and install deps: `python3 -m venv .venv && .venv/bin/pip install -r priv/python/requirements.txt`
- Export the interpreter for Mix so workers reuse it: `export SNAKEPIT_PYTHON="$PWD/.venv/bin/python3"`
- Run bridge tests with the bundled modules on the path: `PYTHONPATH=priv/python .venv/bin/pytest priv/python/tests -q`
- `make test` wraps these steps; run it when debugging cross-language failures
3. **Compilation Warnings**
- Protocol buffer regeneration may be needed
- Run `mix grpc.gen` to regenerate Elixir bindings
### Telemetry Verification Checklist
- `mix test` – exercises the Elixir OpenTelemetry spans/metrics wiring (fails fast if the Python bridge cannot import OTEL SDK).
- `PYTHONPATH=priv/python .venv/bin/pytest priv/python/tests/test_telemetry.py -q` – validates the Python span helpers and correlation filter.
- `curl http://localhost:9568/metrics` – shows Prometheus metrics after enabling the reporter with `config :snakepit, telemetry_metrics: %{prometheus: %{enabled: true}}`.
- Set `SNAKEPIT_OTEL_ENDPOINT=http://collector:4318` (or `SNAKEPIT_OTEL_CONSOLE=true`) to watch trace exports when running end-to-end examples.
## Related Documentation
- [Main README](README.md) - Project overview
- [Unified gRPC Bridge](README_UNIFIED_GRPC_BRIDGE.md) - Protocol details
- [Main README](README.md) - Implementation status