Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
feat(tests): enhance test parallelization (#199)
Johannes Grumböck4a836f32b817
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 5ba8f5e4..00a471f2 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -31,7 +31,7 @@ jobs:cache: "pip"- name: Install dependencies- run: pip install -e . && pip install -r requirements.txt boto3 pytest duckdb docker cbor2 pyyaml cryptography+ run: pip install -e . && pip install -r requirements.txt boto3 pytest pytest-xdist duckdb docker cbor2 pyyaml cryptography- name: Start MiniStackrun: |@@ -39,5 +39,8 @@ jobs:sleep 3curl -sf http://localhost:4566/_ministack/health- - name: Run tests- run: pytest tests/ -v --tb=short+ - name: Run tests (parallel safe set)+ run: pytest tests/ -v -n 3 --dist=loadfile -m "not serial"++ - name: Run tests (serial global-state set)+ run: pytest tests/ -v --tb=short -m "serial"diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex d362d8d8..b0986df8 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -139,10 +139,13 @@ def test_myservice_operation_one(mysvc):docker compose up -d# Install test dependencies-pip install boto3 pytest duckdb docker cbor2+pip install boto3 pytest pytest-xdist duckdb docker cbor2-# Run all tests-pytest tests/ -v+# Parallel-safe phase: run tests that are safe to run concurrently+pytest tests/ -v -n 4 --dist=loadfile -m "not serial"++# Serial/global-state phase: run tests that mutate runtime state or require isolation+pytest tests/ -v -m serial# Run a specific servicepytest tests/ -v -k "cognito"diff --git a/pyproject.toml b/pyproject.tomlindex cb5b3323..3ddeb983 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -39,6 +39,7 @@ full = [dev = ["boto3>=1.34","pytest>=8.0",+ "pytest-xdist>=3.6","pytest-cov>=5.0","duckdb>=0.10.0","docker>=7.0.0",diff --git a/tests/conftest.py b/tests/conftest.pyindex f4c0e2a4..e7991473 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -16,7 +16,12 @@ _kwargs = dict(aws_access_key_id="test",aws_secret_access_key="test",region_name=REGION,- config=Config(region_name=REGION, retries={"max_attempts": 0}),+ # Hardcoded retry and pool settings to reduce transient connection flakes+ config=Config(+ region_name=REGION,+ retries={"mode": "standard"},+ max_pool_connections=50,+ ),)@@ -24,6 +29,29 @@ def make_client(service):return boto3.client(service, **_kwargs)+_SERIAL_TESTS = {+ "tests/test_athena.py::test_athena_engine_mock_via_config",+ "tests/test_lambda.py::test_lambda_reset_terminates_workers",+ "tests/test_ministack.py::test_ministack_config_invalid_key_ignored",+ "tests/test_sfn.py::test_sfn_mock_config_return",+ "tests/test_sfn.py::test_sfn_mock_config_throw",+}+++def pytest_configure(config):+ config.addinivalue_line(+ "markers",+ "serial: test must run in a dedicated sequential phase",+ )+++def pytest_collection_modifyitems(config, items):+ for item in items:+ nodeid = item.nodeid.split("[", 1)[0]+ if nodeid in _SERIAL_TESTS:+ item.add_marker("serial")++@pytest.fixture(scope="session", autouse=True)def reset_server():"""Reset all server state once before the test session starts."""@@ -211,7 +239,8 @@ def sfn_sync():region_name=REGION,config=BotoConfig(region_name=REGION,- retries={"max_attempts": 0},+ retries={"mode": "standard"},+ max_pool_connections=50,inject_host_prefix=False,),)@@ -236,7 +265,8 @@ def sd():region_name=REGION,config=BotoConfig(region_name=REGION,- retries={"max_attempts": 0},+ retries={"mode": "standard"},+ max_pool_connections=50,inject_host_prefix=False,),)diff --git a/tests/test_cfn.py b/tests/test_cfn.pyindex d4f993cd..d43860d5 100644--- a/tests/test_cfn.py+++ b/tests/test_cfn.py@@ -8,7 +8,7 @@ import pytestfrom botocore.exceptions import ClientErrorimport uuid as _uuid_mod-def _wait_stack(cfn, name, timeout=10):+def _wait_stack(cfn, name, timeout=30):"""Poll until stack reaches terminal status."""deadline = time.time() + timeoutwhile time.time() < deadline: