Skip to content

Leechael/dstack-gateway-test-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test Backend - Multi-Protocol Server

A comprehensive test server that supports all major HTTP-based protocols including PROXY Protocol v1 and v2.

Features

Protocol Support

  • HTTP/1.1 and HTTP/2
  • WebSocket
  • Server-Sent Events (SSE)
  • GraphQL
  • gRPC
  • Long Polling
  • Chunked Transfer Encoding
  • WebDAV
  • PROXY Protocol v1 & v2

Quick Start

Using Make (Recommended)

# Show all available commands
make help

# Quick start with Docker
make docker-run   # Start all services
make docker-test  # Run tests
make docker-stop  # Stop services

# Local development
make build        # Build binary
make run          # Run locally
make test         # Test local server

Manual Setup

1. Local Build and Run

# Build
chmod +x build-local.sh
./build-local.sh

# Run (choose based on your system)
./test-backend-darwin-arm64  # macOS M1/M2
./test-backend-darwin        # macOS Intel
./test-backend-linux         # Linux

# Test
chmod +x test-local.sh
./test-local.sh

2. Docker Build and Run

# Build image
docker build -t test-backend:latest .

# Run with docker-compose
docker-compose -f docker-compose.local.yaml up -d

# Run tests
./test-local.sh

# View logs
docker-compose -f docker-compose.local.yaml logs -f

# Stop
docker-compose -f docker-compose.local.yaml down

Port Configuration

Port Protocol Description
8080 HTTP Main server (HTTP/WebSocket/SSE/GraphQL)
8081 HTTP PROXY Protocol listener
50051 gRPC gRPC service
8888 HTTP Nginx reverse proxy (docker-compose)
8444 HTTP HAProxy with PROXY Protocol (docker-compose)

Testing Endpoints

Basic HTTP

curl http://localhost:8080/
curl -X POST http://localhost:8080/ -d "test=data"

WebSocket

# With websocat
websocat ws://localhost:8080/ws

# With curl
curl -i -N \
  -H "Connection: Upgrade" \
  -H "Upgrade: websocket" \
  -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
  -H "Sec-WebSocket-Version: 13" \
  http://localhost:8080/ws

Server-Sent Events

curl -N -H "Accept: text/event-stream" http://localhost:8080/events

GraphQL

curl -X POST http://localhost:8080/graphql \
  -H "Content-Type: application/json" \
  -d '{"query":"{test}"}'

Long Polling

curl http://localhost:8080/long-poll

Chunked Transfer

curl --raw http://localhost:8080/chunked

WebDAV

curl -X PROPFIND http://localhost:8080/dav/

PROXY Protocol Testing

# Through HAProxy (docker-compose)
curl http://localhost:8444/proxy-v1/test  # PROXY v1
curl http://localhost:8444/proxy-v2/test  # PROXY v2

# Direct to PROXY port
curl http://localhost:8081/

Protocol Detection

The server can detect which protocol is being used:

curl http://localhost:8080/detect

Test Results

View all test results collected during the session:

curl http://localhost:8080/test-results | jq

Development

Project Structure

test-backend/
├── main.go                   # Main server code
├── go.mod                    # Go module definition
├── Dockerfile               # Container image
├── Makefile                 # Build automation
├── build-local.sh           # Local build script
├── test-local.sh            # Test script
├── docker-compose.local.yaml # Local testing stack
├── nginx-test.conf          # Nginx test config
├── haproxy-test.cfg         # HAProxy test config
└── README.md                # This file

Adding New Protocols

  1. Add handler in main.go
  2. Register route in setupRoutes()
  3. Add test case in test-local.sh
  4. Update documentation

Troubleshooting

Port Already in Use

# Find process using port
lsof -i :8080

# Kill process
kill -9 <PID>

Docker Build Issues

# Clean rebuild
docker-compose -f docker-compose.local.yaml down -v
docker-compose -f docker-compose.local.yaml build --no-cache

Test Failures

  • Ensure server is running: curl http://localhost:8080/health
  • Check logs: docker-compose logs test-backend
  • Verify ports are exposed: docker ps

Dependencies

  • Go 1.21+
  • Docker & Docker Compose (optional)
  • Test tools (optional):
    • websocat - WebSocket testing
    • grpcurl - gRPC testing
    • jq - JSON processing

Install test tools:

make install-tools  # macOS only

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published