|
| 1 | +name: Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - dev |
| 8 | + - release-* |
| 9 | + - feat-* |
| 10 | + - ci-* |
| 11 | + - refactor-* |
| 12 | + - fix-* |
| 13 | + - test-* |
| 14 | + paths: |
| 15 | + - '.github/workflows/test.yml' |
| 16 | + - '**/Cargo.toml' |
| 17 | + - '**/*.rs' |
| 18 | + - '**/*.hurl' |
| 19 | + - 'run_tests.sh' |
| 20 | + - 'tests/**' |
| 21 | + pull_request: |
| 22 | + branches: [ main ] |
| 23 | + |
| 24 | +env: |
| 25 | + CARGO_TERM_COLOR: always |
| 26 | + RUST_BACKTRACE: 1 |
| 27 | + |
| 28 | +jobs: |
| 29 | + test: |
| 30 | + name: Test Suite |
| 31 | + runs-on: ubuntu-latest |
| 32 | + strategy: |
| 33 | + matrix: |
| 34 | + rust: [1.90.0] |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout code |
| 38 | + uses: actions/checkout@v5 |
| 39 | + |
| 40 | + - name: Start httpbin |
| 41 | + run: | |
| 42 | + # Use official httpbin image |
| 43 | + docker run -d \ |
| 44 | + --name httpbin \ |
| 45 | + -p 8888:80 \ |
| 46 | + kennethreitz/httpbin:latest |
| 47 | +
|
| 48 | + # Wait for service to be ready |
| 49 | + echo "Waiting for httpbin to be ready..." |
| 50 | + for i in {1..30}; do |
| 51 | + if curl -f http://localhost:8888/get > /dev/null 2>&1; then |
| 52 | + echo "✅ httpbin is ready!" |
| 53 | + break |
| 54 | + fi |
| 55 | + if [ $i -eq 30 ]; then |
| 56 | + echo "❌ httpbin failed to start" |
| 57 | + docker logs httpbin |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | + sleep 2 |
| 61 | + done |
| 62 | +
|
| 63 | + - name: Start json-server |
| 64 | + run: | |
| 65 | + # Use Node.js official image to run json-server |
| 66 | + docker run -d \ |
| 67 | + --name json-api \ |
| 68 | + -p 8889:3000 \ |
| 69 | + -v ${{ github.workspace }}/tests/mock-data:/data:ro \ |
| 70 | + -w /data \ |
| 71 | + node:18-alpine \ |
| 72 | + sh -c "npm install -g json-server@0.17.4 && json-server --host 0.0.0.0 --port 3000 db.json" |
| 73 | +
|
| 74 | + # Wait for service to be ready |
| 75 | + echo "Waiting for json-api to be ready..." |
| 76 | + for i in {1..60}; do |
| 77 | + if curl -f http://localhost:8889/posts > /dev/null 2>&1; then |
| 78 | + echo "✅ json-api is ready!" |
| 79 | + break |
| 80 | + fi |
| 81 | + if [ $i -eq 60 ]; then |
| 82 | + echo "❌ json-api failed to start" |
| 83 | + docker logs json-api |
| 84 | + exit 1 |
| 85 | + fi |
| 86 | + sleep 2 |
| 87 | + done |
| 88 | +
|
| 89 | + - name: Start WebSocket echo server |
| 90 | + run: | |
| 91 | + # Use ultra-robust Python WebSocket echo server with manual message loop |
| 92 | + cat > ws-echo.py << 'EOF' |
| 93 | + import asyncio |
| 94 | + import websockets |
| 95 | + import logging |
| 96 | + import sys |
| 97 | +
|
| 98 | + logging.basicConfig( |
| 99 | + level=logging.INFO, |
| 100 | + format='%(asctime)s - %(levelname)s - %(message)s', |
| 101 | + stream=sys.stdout |
| 102 | + ) |
| 103 | + logger = logging.getLogger(__name__) |
| 104 | +
|
| 105 | + async def echo(websocket): |
| 106 | + client_addr = websocket.remote_address |
| 107 | + logger.info(f"✅ New connection from {client_addr}") |
| 108 | +
|
| 109 | + message_count = 0 |
| 110 | + try: |
| 111 | + # Manual receive loop with explicit error checking |
| 112 | + while True: |
| 113 | + try: |
| 114 | + # Wait for message with timeout |
| 115 | + message = await asyncio.wait_for( |
| 116 | + websocket.recv(), |
| 117 | + timeout=60.0 # 60 second timeout |
| 118 | + ) |
| 119 | +
|
| 120 | + message_count += 1 |
| 121 | + msg_type = "binary" if isinstance(message, bytes) else "text" |
| 122 | + msg_size = len(message) |
| 123 | +
|
| 124 | + logger.info(f"📨 Received {msg_type} message #{message_count}: {msg_size} bytes from {client_addr}") |
| 125 | +
|
| 126 | + # Echo back immediately |
| 127 | + await websocket.send(message) |
| 128 | + logger.info(f"📤 Echoed {msg_type} message #{message_count}: {msg_size} bytes to {client_addr}") |
| 129 | +
|
| 130 | + except asyncio.TimeoutError: |
| 131 | + logger.warning(f"⏰ Timeout waiting for message from {client_addr}") |
| 132 | + continue |
| 133 | + except websockets.exceptions.ConnectionClosedOK: |
| 134 | + logger.info(f"✅ Connection closed normally by {client_addr} after {message_count} messages") |
| 135 | + break |
| 136 | + except websockets.exceptions.ConnectionClosedError as e: |
| 137 | + logger.warning(f"⚠️ Connection closed with error from {client_addr}: {e}") |
| 138 | + break |
| 139 | +
|
| 140 | + except Exception as e: |
| 141 | + logger.error(f"❌ Unexpected error handling {client_addr}: {e}", exc_info=True) |
| 142 | + finally: |
| 143 | + logger.info(f"🔚 Handler ended for {client_addr} (processed {message_count} messages)") |
| 144 | +
|
| 145 | + async def main(): |
| 146 | + host = "0.0.0.0" |
| 147 | + port = 8890 |
| 148 | +
|
| 149 | + logger.info(f"🚀 Starting WebSocket echo server on {host}:{port}") |
| 150 | +
|
| 151 | + # Start server with very permissive settings |
| 152 | + async with websockets.serve( |
| 153 | + echo, |
| 154 | + host, |
| 155 | + port, |
| 156 | + ping_interval=None, # Disable ping/pong (let client handle it) |
| 157 | + ping_timeout=None, # No ping timeout |
| 158 | + close_timeout=10, # 10 seconds for close handshake |
| 159 | + max_size=10 * 1024 * 1024, # 10MB max message |
| 160 | + max_queue=32, # Max 32 queued messages |
| 161 | + compression=None # Disable compression for simplicity |
| 162 | + ): |
| 163 | + logger.info(f"✅ WebSocket echo server is ready and listening") |
| 164 | + await asyncio.Future() # Run forever |
| 165 | +
|
| 166 | + if __name__ == "__main__": |
| 167 | + try: |
| 168 | + asyncio.run(main()) |
| 169 | + except KeyboardInterrupt: |
| 170 | + logger.info("🛑 Server stopped by user") |
| 171 | + sys.exit(0) |
| 172 | + EOF |
| 173 | +
|
| 174 | + docker run -d \ |
| 175 | + --name ws-echo \ |
| 176 | + -p 8890:8890 \ |
| 177 | + -v ${{ github.workspace }}/ws-echo.py:/ws-echo.py:ro \ |
| 178 | + python:3.11-alpine \ |
| 179 | + sh -c "pip install websockets && python /ws-echo.py" |
| 180 | +
|
| 181 | + # Wait for service to be ready - WebSocket service starts quickly |
| 182 | + echo "Waiting for ws-echo to be ready..." |
| 183 | + sleep 10 |
| 184 | +
|
| 185 | + # Check if container is running |
| 186 | + if docker ps | grep -q ws-echo; then |
| 187 | + echo "✅ ws-echo container is running!" |
| 188 | + else |
| 189 | + echo "❌ ws-echo container failed to start" |
| 190 | + docker logs ws-echo |
| 191 | + exit 1 |
| 192 | + fi |
| 193 | +
|
| 194 | + - name: Install Rust-stable |
| 195 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 196 | + with: |
| 197 | + toolchain: ${{ matrix.rust }} |
| 198 | + |
| 199 | + - name: Cache Rust dependencies |
| 200 | + uses: Swatinem/rust-cache@v2 |
| 201 | + with: |
| 202 | + cache-on-failure: true |
| 203 | + |
| 204 | + - name: Install Hurl |
| 205 | + run: | |
| 206 | + VERSION="5.0.1" |
| 207 | + curl -LO https://github.com/Orange-OpenSource/hurl/releases/download/${VERSION}/hurl_${VERSION}_amd64.deb |
| 208 | + sudo dpkg -i hurl_${VERSION}_amd64.deb |
| 209 | +
|
| 210 | + - name: Install SQLite |
| 211 | + run: sudo apt-get update && sudo apt-get install -y sqlite3 |
| 212 | + |
| 213 | + - name: Verify services are running |
| 214 | + run: | |
| 215 | + echo "Checking httpbin..." |
| 216 | + curl -f http://localhost:8888/get |
| 217 | +
|
| 218 | + echo "Checking json-api..." |
| 219 | + curl -f http://localhost:8889/posts |
| 220 | +
|
| 221 | + echo "Checking ws-echo (WebSocket service - checking port)..." |
| 222 | + if timeout 5 bash -c 'cat < /dev/null > /dev/tcp/localhost/8890'; then |
| 223 | + echo "✅ ws-echo port 8890 is listening" |
| 224 | + else |
| 225 | + echo "❌ ws-echo port 8890 is not accessible" |
| 226 | + docker logs ws-echo |
| 227 | + exit 1 |
| 228 | + fi |
| 229 | +
|
| 230 | + - name: Run tests |
| 231 | + env: |
| 232 | + USE_DOCKER_SERVICES: false # Services already running via GitHub Actions |
| 233 | + run: | |
| 234 | + chmod +x run_tests.sh |
| 235 | + ./run_tests.sh |
| 236 | +
|
| 237 | + - name: Upload test results |
| 238 | + if: failure() |
| 239 | + uses: actions/upload-artifact@v4 |
| 240 | + with: |
| 241 | + name: test-logs |
| 242 | + path: | |
| 243 | + *.log |
| 244 | + sessions.db |
| 245 | +
|
| 246 | + - name: Cleanup test services |
| 247 | + if: always() |
| 248 | + run: | |
| 249 | + docker stop httpbin || true |
| 250 | + docker rm httpbin || true |
| 251 | + docker stop json-api || true |
| 252 | + docker rm json-api || true |
| 253 | + docker stop ws-echo || true |
| 254 | + docker rm ws-echo || true |
0 commit comments