|
| 1 | +import importlib |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | + |
| 6 | +pytestmark = pytest.mark.usefixtures("worker_app") |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +def worker_app(monkeypatch): |
| 11 | + monkeypatch.setenv("MODAL_ENVIRONMENT", "testing") |
| 12 | + from policyengine_household_api.modal_release import worker_app |
| 13 | + |
| 14 | + return importlib.reload(worker_app) |
| 15 | + |
| 16 | + |
| 17 | +def test_worker_function_options_keep_main_workers_warm(worker_app): |
| 18 | + options = worker_app.worker_function_options(modal_environment="main") |
| 19 | + |
| 20 | + assert options["min_containers"] == 3 |
| 21 | + assert options["buffer_containers"] == 2 |
| 22 | + assert options["scaledown_window"] == 600 |
| 23 | + |
| 24 | + |
| 25 | +def test_worker_function_options_do_not_keep_staging_workers_warm(): |
| 26 | + from policyengine_household_api.modal_release.worker_app import ( |
| 27 | + worker_function_options, |
| 28 | + ) |
| 29 | + |
| 30 | + options = worker_function_options(modal_environment="staging") |
| 31 | + |
| 32 | + assert "min_containers" not in options |
| 33 | + assert "buffer_containers" not in options |
| 34 | + assert options["scaledown_window"] == 300 |
| 35 | + |
| 36 | + |
| 37 | +def test_worker_function_options_do_not_keep_workers_warm_without_env( |
| 38 | + monkeypatch, |
| 39 | +): |
| 40 | + monkeypatch.delenv("MODAL_ENVIRONMENT", raising=False) |
| 41 | + from policyengine_household_api.modal_release.worker_app import ( |
| 42 | + worker_function_options, |
| 43 | + ) |
| 44 | + |
| 45 | + with pytest.raises(RuntimeError, match="MODAL_ENVIRONMENT"): |
| 46 | + worker_function_options(modal_environment=None) |
0 commit comments