zeroae / zeroae/zae-limiter

✨ Add In-Memory backend for unit testing

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

Nobody has claimed this yet.

api-design area/limiter testing
Dominant language
Python
Stars
0
Forks
0
Avg merge
6h 51m
Merged PRs (30d)
104

Description

Summary

Add an in-memory backend for fast unit tests without any external dependencies (no moto, no Docker).

Motivation

  • Fastest possible test execution
  • No moto dependency for simple tests
  • Easy to set up test fixtures
  • Predictable behavior for unit tests

Usage

from zae_limiter import RateLimiter
from zae_limiter.backends.memory import InMemoryRepository

repo = InMemoryRepository()
limiter = RateLimiter(repository=repo)

# Pre-populate for tests
repo.seed_entity("test-user", buckets={...})

Features

class InMemoryRepository:
    def __init__(self):
        self._entities: dict[str, Entity] = {}
        self._buckets: dict[str, BucketState] = {}
    
    # Test helpers
    def seed_entity(self, entity_id: str, **kwargs) -> Entity: ...
    def seed_bucket(self, entity_id: str, resource: str, limit: Limit, tokens: int) -> BucketState: ...
    def reset(self) -> None: ...
    def get_all_entities(self) -> list[Entity]: ...

Limitations

  • Single-process only
  • No persistence
  • Doesn't test real DynamoDB behavior (use moto for integration tests)

Dependencies

  • #150 - Repository Protocol extraction (must be completed first)

Acceptance Criteria

  • InMemoryRepository implements RepositoryProtocol
  • Test helper methods for seeding data
  • Thread-safe
  • Zero external dependencies
  • Documentation on when to use vs moto

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

Start by reviewing the RepositoryProtocol work in #150 and the existing repository behavior that the in-memory backend must match. Implement InMemoryRepository with the listed seed, reset, and retrieval helpers, then verify protocol compliance, thread safety, zero external dependencies, and documentation explaining when to use it instead of moto.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.