From 693b06d8f4a4aebeade92f99e75a7330aae72dae Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Wed, 4 Mar 2026 13:14:46 +0100 Subject: [PATCH] test: fix flaky request timing tests --- .../sentry/rack/capture_exceptions_spec.rb | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb b/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb index f903c9158..8a037595b 100644 --- a/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb +++ b/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb @@ -676,13 +676,15 @@ def will_be_sampled_by_sdk context "with X-Request-Start header" do it "attaches queue time to transaction" do - timestamp = Time.now.to_f - 0.05 # 50ms ago - env["HTTP_X_REQUEST_START"] = "t=#{timestamp}" + Timecop.freeze do + timestamp = Time.now.to_f - 0.05 # 50ms ago + env["HTTP_X_REQUEST_START"] = "t=#{timestamp}" - stack.call(env) + stack.call(env) - queue_time = transaction.contexts.dig(:trace, :data, 'http.server.request.time_in_queue') - expect(queue_time).to be_within(10).of(50) + queue_time = transaction.contexts.dig(:trace, :data, 'http.server.request.time_in_queue') + expect(queue_time).to be_within(10).of(50) + end end it "subtracts puma.request_body_wait" do @@ -725,14 +727,16 @@ def will_be_sampled_by_sdk end it "handles different timestamp formats" do - # Heroku/HAProxy microseconds format - timestamp_us = ((Time.now.to_f - 0.03) * 1_000_000).to_i - env["HTTP_X_REQUEST_START"] = "t=#{timestamp_us}" + Timecop.freeze do + # Heroku/HAProxy microseconds format + timestamp_us = ((Time.now.to_f - 0.03) * 1_000_000).to_i + env["HTTP_X_REQUEST_START"] = "t=#{timestamp_us}" - stack.call(env) + stack.call(env) - queue_time = transaction.contexts.dig(:trace, :data, 'http.server.request.time_in_queue') - expect(queue_time).to be_within(10).of(30) + queue_time = transaction.contexts.dig(:trace, :data, 'http.server.request.time_in_queue') + expect(queue_time).to be_within(10).of(30) + end end end