gunicorn/tests/docker/per_app_allocation
Benoit Chesneau 54d38afddf test: unblock docker fixtures on macOS hosts
- per_app_allocation: move host port from 8001 to 28001. OrbStack reserves
  8001 on macOS for vcom-tunnel which makes 'Bind: port already allocated'
  the default failure mode.
- dirty_ttin_ttou: pin BASE_URL to 127.0.0.1 instead of 'localhost'. macOS
  resolves 'localhost' to ::1 first; Docker Desktop / OrbStack only forward
  host ports on IPv4 so the IPv6 attempt resets and the test fixture treats
  the service as unhealthy.
- dirty_ttin_ttou: add setproctitle to the test image. The TTIN/TTOU tests
  count workers via 'pgrep -f dirty-worker', which only matches once
  gunicorn's util._setproctitle has actually renamed the processes.
2026-05-04 09:47:38 +02:00
..
2026-03-25 13:33:49 +01:00

Per-App Worker Allocation E2E Tests

End-to-end Docker-based tests for the per-app worker allocation feature.

Overview

These tests verify that:

  • Apps with worker limits are only loaded on the specified number of workers
  • Requests are routed only to workers that have the target app loaded
  • Round-robin distribution works correctly within limited worker sets
  • Worker crash scenarios maintain correct app allocation
  • Class attribute workers=N is respected
  • Config-based :N overrides class attributes

Configuration

The tests use 4 dirty workers with 3 apps:

  • LightweightApp: No limit (loads on all 4 workers)
  • HeavyApp: workers=2 class attribute (loads on 2 workers)
  • ConfigLimitedApp: :1 config (loads on 1 worker)

Running Tests

# From this directory
cd tests/docker/per_app_allocation

# Build the Docker image
docker compose build

# Run all tests
pytest test_per_app_e2e.py -v

# Run specific test
pytest test_per_app_e2e.py::TestPerAppAllocation::test_config_limited_app_uses_one_worker -v

Test Categories

TestPerAppAllocation

  • Tests basic functionality of per-app worker allocation
  • Verifies round-robin distribution
  • Tests app accessibility

TestPerAppWorkerCrash

  • Tests behavior when workers crash
  • Verifies app recovery after worker respawn

TestPerAppLogs

  • Verifies logging output contains expected information

Requirements

  • Docker and Docker Compose
  • Python 3.8+
  • pytest
  • requests

Notes

  • Tests run on port 28001 to avoid conflicts with the existing dirty_arbiter tests on 8000 and with macOS Docker alternatives that often reserve port 8001 (e.g., OrbStack's vcom-tunnel)
  • The container uses a keep-alive wrapper to allow testing worker crash scenarios