Skip to content

Add tests for InMemoryIdempotencyStore TTL expiry and in-flight transitions #351

@thlpkee20-wq

Description

@thlpkee20-wq

Description

InMemoryIdempotencyStore in src/middleware/idempotency.ts exposes checkAndReserve, save, release, and a pruneExpired path driven by ttlMs, but the expiry and in-flight state machine need exhaustive tests. Add unit tests that exercise the newinflightcached transitions and TTL-based eviction with a controllable clock.

Requirements and context

  • Must be secure, tested, and documented
  • Should be efficient and easy to review
  • Relevant code: src/middleware/idempotency.ts, src/middleware/idempotency.test.ts
  • Expired cached records must be treated as new and never returned as cached

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/idempotency-store-ttl
  • Implement changes
    • Use fake timers to advance past ttlMs
    • Assert reserve → inflight, save → cached, release frees the key
    • Assert pruning removes expired entries on access
  • Validate security and correctness assumptions

Test and commit

  • Run tests
    • npm test
  • Cover edge cases
    • Zero/undefined TTL never expires, double release, save without reserve, concurrent reserve
  • Include test output and notes

Example commit message

test: cover idempotency store TTL and state transitions

Guidelines

  • Minimum 95 percent test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions