zeroae / zeroae/zae-limiter

✅ Add unit tests for Lambda worker handler locustfile processing

Open
#357 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/loadtest testing
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 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.