# Compression Testing Suite

This directory contains scripts and configurations to test gRPC compression across Go, TypeScript, and Python SDKs.

## Overview

Tests measure network traffic bytes for each SDK comparing:

- **Baseline**: Main branch (no compression)
- **With Compression**: Current branch (compression enabled)

## Docker Image Tags

All images use the format: `{sdk}-{state}-compression`

- `go-disabled-compression` / `go-enabled-compression`
- `typescript-disabled-compression` / `typescript-enabled-compression`
- `python-disabled-compression` / `python-enabled-compression`
- `engine-disabled-compression` / `engine-enabled-compression`

## Build Instructions

### Step 1: Build Baseline Images (Main Branch)

**Important:** All docker build commands must be run from the repository root, not from the testing directory.

```bash
# Checkout main branch
git checkout main

# Navigate to repository root (if not already there)
cd /path/to/hatchet

# Build Go SDK
docker build -t go-disabled-compression -f hack/dev/compression-test/Dockerfile.client-go .

# Build TypeScript SDK
docker build -t typescript-disabled-compression -f hack/dev/compression-test/Dockerfile.client-ts .

# Build Python SDK
docker build -t python-disabled-compression -f hack/dev/compression-test/Dockerfile.client-python .

# Build Engine (optional - you may manage this separately)
# docker build -t engine-disabled-compression -f Dockerfile .
```

### Step 2: Build Compression Images (Current Branch)

```bash
# Checkout your compression branch
git checkout <your-compression-branch>

# Navigate to repository root
cd /path/to/hatchet

# Build Go SDK
docker build -t go-enabled-compression -f hack/dev/compression-test/Dockerfile.client-go .

# Build TypeScript SDK
docker build -t typescript-enabled-compression -f hack/dev/compression-test/Dockerfile.client-ts .

# Build Python SDK
docker build -t python-enabled-compression -f hack/dev/compression-test/Dockerfile.client-python .

# Build Engine (optional - you may manage this separately)
# docker build -t engine-enabled-compression -f Dockerfile .
```

## Running Tests

### Prerequisites

1. **Engine must be running**: Start your Hatchet engine separately (not managed by these scripts)

   - The engine should be accessible at the host/port you specify in `HATCHET_CLIENT_HOST_PORT`

2. **Set required environment variables**:

   ```bash
   export HATCHET_CLIENT_TOKEN="your-token-here"
   export HATCHET_CLIENT_HOST_PORT="localhost:7070"  # gRPC address where your engine is running
   ```

   **Optional environment variables**:

   ```bash
   export HATCHET_CLIENT_SERVER_URL="http://localhost:8080"  # HTTP server URL (for Go SDK, defaults to http://localhost:8080)
   export HATCHET_CLIENT_API_URL="http://localhost:8080"     # API URL (for TypeScript SDK, defaults to http://localhost:8080)
   export HATCHET_CLIENT_NAMESPACE="compression-test"        # Namespace (optional, defaults to compression-test)
   ```

   **Note**:

   - `HATCHET_CLIENT_TENANT_ID` is extracted from the token automatically, so you don't need to set it.
   - The scripts use `host` network mode, so containers can access your engine running on the host.

### Quick Start

```bash
# Navigate to testing directory
cd hack/dev/compression-test

# Run setup (creates network and directories)
./scripts/setup.sh

# Run all baseline tests
./scripts/run_all_tests.sh disabled

# Switch engine to compression version, then run compression tests
./scripts/run_all_tests.sh enabled

# Generate comparison report
./scripts/generate_report.sh
```

### Individual SDK Tests

```bash
# Test Go SDK (baseline)
./scripts/run_test.sh go disabled

# Test Go SDK (compression)
./scripts/run_test.sh go enabled

# Test TypeScript SDK
./scripts/run_test.sh typescript disabled
./scripts/run_test.sh typescript enabled

# Test Python SDK
./scripts/run_test.sh python disabled
./scripts/run_test.sh python enabled
```

## Test Parameters

All tests use standardized parameters:

- Duration: 60 seconds
- Events per second: 10
- Payload size: 100KB
- DAG steps: 1
- Event fanout: 1

## Results

Results are saved in `results/` directory:

- `results/baseline/` - Baseline test results
- `results/compressed/` - Compression test results

Final comparison report is generated by `scripts/generate_report.sh`
