From 30f36455ae792df1f61b12d7e5b3e1a63cffc867 Mon Sep 17 00:00:00 2001 From: Philipp Thun Date: Wed, 4 Nov 2026 22:22:46 +0100 Subject: [PATCH] Freeze time in ExpiringRequestCounter new-user spec The mock_redis store records expiry as now + expires_in and reads it back via TTL. When the SET and TTL reads fall on different seconds, the TTL is one low and the example failed intermittently. Freeze time around the increment, like the recurring-user example, so both reads see the same instant. --- spec/unit/middleware/rate_limiter_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/unit/middleware/rate_limiter_spec.rb b/spec/unit/middleware/rate_limiter_spec.rb index 4b337e608d8..80a6aae57c3 100644 --- a/spec/unit/middleware/rate_limiter_spec.rb +++ b/spec/unit/middleware/rate_limiter_spec.rb @@ -419,9 +419,11 @@ module Middleware end it 'returns count=1 and expires_in for a new user' do - count, expires_in = expiring_request_counter.increment(user_guid, reset_interval_in_minutes, logger) - expect(count).to eq(1) - expect(expires_in).to eq(stubbed_expires_in) + Timecop.freeze do + count, expires_in = expiring_request_counter.increment(user_guid, reset_interval_in_minutes, logger) + expect(count).to eq(1) + expect(expires_in).to eq(stubbed_expires_in) + end end it 'returns count=2 and expires_in minus the elapsed time for a recurring user' do