✅ Add unit tests for Lambda worker handler locustfile processing
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- Avg merge
- 6h 51m
- Merged PRs (30d)
- 104
Description
Description
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 overLOCUSTFILEenv var for module path resolution - Test that the default module path is
locustfilewhen neitherconfig["locustfile"]norLOCUSTFILEenv 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_classesis trimmed (e.g.,"ClassA, ClassB")
_configure_boto3_pool
- Test that
_configure_boto3_poolis idempotent (calling twice does not re-patch) - Test that the patched
boto3.Session.clientappliesmax_pool_connectionsconfig todynamodbservice calls - Test that non-dynamodb service calls are not affected by the patch
_run_headless
- Test that
_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) - Test that
_run_headlessstops early whencontext.get_remaining_time_in_millis()returns a value below the shutdown buffer - Test that
_run_headlesscalculates shutdown buffer asshutdown_buffer_pctof initial remaining time
_run_as_worker
- Test that
_run_as_workergenerates a worker ID fromcontext.aws_request_idwhen available - Test that
_run_as_workergenerates a UUID-based worker ID when context has noaws_request_id - Test that
_run_as_workersetsLOCUST_UNIQUE_IDenvironment variable before creating the runner - Test that
_run_as_workerquits gracefully when Lambda timeout approaches (remaining time < shutdown buffer) - Test that
_run_as_workerreturns{"status": "worker_completed", "worker_id": ...}
Notes
- All tests should use mocks for
locustimports (Environment,User, etc.) to avoid gevent monkey-patching in the test process, following the existing_FakeUserBasepattern intest_worker.py - Tests belong in
tests/unit/loadtest/test_worker.py, extending the existing test file - Use
pytest.mark.geventmarker consistent with existing tests in the file
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Extend tests/unit/loadtest/test_worker.py, following the existing TestHandler, _load_user_classes coverage, _FakeUserBase pattern, and pytest.mark.gevent usage. First read src/zae_limiter/loadtest/lambda/worker.py and run the existing worker tests. Done means the listed resolution, discovery, boto3 patching, headless-runner, timeout, worker-ID, environment, and return-value behaviors are covered with mocks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100