Skip to content

[Testing] Add unit tests for backend lib/redis.ts MemoryCache.set/get/del/expire #696

@ogazboiz

Description

@ogazboiz

Join the discussion on Telegram

Why this matters

backend/src/lib/redis.ts includes a hand-rolled MemoryCache class with set/get/del/cleanup/getStats and a 60-second sweep. No tests for the cache itself.

This is the cache that fronts admin metrics, the claimable-amount fingerprinting, and the user-summary cache (indirectly). A bug here silently inflates RPC cost or stale data.

Acceptance criteria

  • Add backend/tests/memory-cache.test.ts (Vitest)
  • Test cases: set+get returns value, set with 0 TTL is immediately expired, expired entries are pruned by cleanup(), del() removes an entry, getStats() reflects hits/misses/itemCount, getMetadata() returns ISO timestamps
  • Don't depend on real-time sleep: use fake timers (vi.useFakeTimers) to advance time
  • Don't touch the Redis pub/sub paths in this issue

Files to touch

  • new backend/tests/memory-cache.test.ts

Out of scope

  • Testing the Redis publisher/subscriber lifecycle

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendBackend related tasksgood first issueGood for newcomerstestingTesting related tasks

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