You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Lambda worker handler (src/zae_limiter/loadtest/lambda/worker.py) has existing unit tests in tests/unit/loadtest/test_worker.py covering handler dispatch (TestHandler) and basic _load_user_classes loading. However, several locustfile processing paths and runtime behaviors lack coverage.
Acceptance Criteria
_load_user_classes locustfile resolution
Test that config["locustfile"] takes precedence over LOCUSTFILE env var for module path resolution
Test that the default module path is locustfile when neither config["locustfile"] nor LOCUSTFILE env var is set
Test that abstract User subclasses (abstract = True) are excluded from auto-discovery results
Test that non-User classes in the module are excluded from auto-discovery results
Test that whitespace in comma-separated user_classes is trimmed (e.g., "ClassA, ClassB")
_configure_boto3_pool
Test that _configure_boto3_pool is idempotent (calling twice does not re-patch)
Test that the patched boto3.Session.client applies max_pool_connections config to dynamodb service calls
Test that non-dynamodb service calls are not affected by the patch
_run_headless
Test that _run_headless loads user classes from config, creates a LocalRunner, starts users, and returns stats dict with expected keys (total_requests, total_failures, avg_response_time, p50, p95, p99, requests_per_second, failure_rate)
Test that _run_headless stops early when context.get_remaining_time_in_millis() returns a value below the shutdown buffer
Test that _run_headless calculates shutdown buffer as shutdown_buffer_pct of initial remaining time
_run_as_worker
Test that _run_as_worker generates a worker ID from context.aws_request_id when available
Test that _run_as_worker generates a UUID-based worker ID when context has no aws_request_id
Test that _run_as_worker sets LOCUST_UNIQUE_ID environment variable before creating the runner
Test that _run_as_worker quits gracefully when Lambda timeout approaches (remaining time < shutdown buffer)
Test that _run_as_worker returns {"status": "worker_completed", "worker_id": ...}
Notes
All tests should use mocks for locust imports (Environment, User, etc.) to avoid gevent monkey-patching in the test process, following the existing _FakeUserBase pattern in test_worker.py
Tests belong in tests/unit/loadtest/test_worker.py, extending the existing test file
Use pytest.mark.gevent marker consistent with existing tests in the file
Description
The Lambda worker handler (
src/zae_limiter/loadtest/lambda/worker.py) has existing unit tests intests/unit/loadtest/test_worker.pycovering handler dispatch (TestHandler) and basic_load_user_classesloading. However, several locustfile processing paths and runtime behaviors lack coverage.Acceptance Criteria
_load_user_classeslocustfile resolutionconfig["locustfile"]takes precedence overLOCUSTFILEenv var for module path resolutionlocustfilewhen neitherconfig["locustfile"]norLOCUSTFILEenv var is setabstract = True) are excluded from auto-discovery resultsuser_classesis trimmed (e.g.,"ClassA, ClassB")_configure_boto3_pool_configure_boto3_poolis idempotent (calling twice does not re-patch)boto3.Session.clientappliesmax_pool_connectionsconfig todynamodbservice calls_run_headless_run_headlessloads user classes from config, creates aLocalRunner, starts users, and returns stats dict with expected keys (total_requests,total_failures,avg_response_time,p50,p95,p99,requests_per_second,failure_rate)_run_headlessstops early whencontext.get_remaining_time_in_millis()returns a value below the shutdown buffer_run_headlesscalculates shutdown buffer asshutdown_buffer_pctof initial remaining time_run_as_worker_run_as_workergenerates a worker ID fromcontext.aws_request_idwhen available_run_as_workergenerates a UUID-based worker ID when context has noaws_request_id_run_as_workersetsLOCUST_UNIQUE_IDenvironment variable before creating the runner_run_as_workerquits gracefully when Lambda timeout approaches (remaining time < shutdown buffer)_run_as_workerreturns{"status": "worker_completed", "worker_id": ...}Notes
locustimports (Environment,User, etc.) to avoid gevent monkey-patching in the test process, following the existing_FakeUserBasepattern intest_worker.pytests/unit/loadtest/test_worker.py, extending the existing test filepytest.mark.geventmarker consistent with existing tests in the file