test(rate_limit): replace FakeRedis with real Redis via docker compose

Description

Replaces the hand-rolled in-memory FakeRedis used in spec/labkit/rate_limit_spec.rb with a real redis:7-alpine instance so the rate-limit specs exercise the same TTL / pipelining / EXPIRE semantics as production. A drift between the fake and the real client is the kind of thing that's most likely to bite us during a rollout of the rate-limit library, so this closes that gap.

What's in here

  • docker-compose.ymlredis:7-alpine on host port 6390 (offset from the default 6379 to avoid colliding with a local GDK / Caproni Redis).
  • spec/support/test_redis.rb — shared client + lazy autostart:
    • On the first reset!, probes the configured URL with a 0.5s timeout.
    • If unreachable, runs docker compose up -d redis (falls back to standalone docker-compose) from the repo root and polls for up to 15s.
    • Registers an at_exit hook to tear the container down again when the test process exits.
    • Autostart is skipped when CI is set, when LABKIT_TEST_REDIS_URL is explicitly set, or when LABKIT_TEST_REDIS_NO_AUTOSTART=1.
  • spec/labkit/rate_limit_spec.rbFakeRedis removed; tests use the real client with FLUSHDB isolation between examples. The Scenario R "does not reset TTL" test now manually shrinks the TTL between calls so it actually proves the invariant (the old assertion would have passed even if EXPIRE had been called again). The "redis error" matrix case still uses instance_double(Redis) so it can deterministically raise without depending on container state.
  • .gitlab-ci.ymlredis:7-alpine declared as a service (alias redis) and LABKIT_TEST_REDIS_URL=redis://redis:6379/0 set on both ruby-versions and legacy-ruby-versions jobs.
  • README.md — developer setup section updated to describe the autostart behaviour and the opt-out env vars.

Verified locally

  • docker compose down → empty docker psbundle exec rspec spec/labkit/rate_limit_spec.rbTestRedis: starting Redis… → 25/25 pass → TestRedis: stopping Redis… → empty docker ps again.
  • Full rate-limit suite (spec/labkit/rate_limit_spec.rb + spec/labkit/rate_limit/) passes 254/254 against the real Redis.

Merge request reports

Loading