Skip to content

Commit 2fd7f50

Browse files
committed
fix(active_job): calc latency to reduce flakiness
1 parent 46b8248 commit 2fd7f50

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

sentry-rails/spec/active_job/shared_examples/tracing/messaging_span_data.rb

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,13 @@ def perform
6464
end
6565

6666
it "records messaging.message.receive.latency in milliseconds", skip: RAILS_VERSION < 6.1 do
67-
successful_job.perform_later
67+
base = Time.current
6868

69-
# Older Rails versions truncate Time.now to whole seconds inside `travel`
70-
# (no `with_usec:` option until 7.0+), so the measured latency can be up
71-
# to ~999ms below the travel delta. Widen the tolerance accordingly.
72-
if RAILS_VERSION > 7.0
73-
travel(5.seconds, with_usec: true) { drain }
74-
tolerance = 50
75-
else
76-
travel(5.seconds) { drain }
77-
tolerance = 1100
78-
end
69+
travel_to(base) { successful_job.perform_later }
70+
travel_to(base + 5.seconds) { drain }
7971

8072
latency = consumer_transaction.contexts.dig(:trace, :data, "messaging.message.receive.latency")
81-
expect(latency).to be_a(Integer)
82-
expect(latency).to be_within(tolerance).of(5_000)
73+
74+
expect(latency).to eq(5_000)
8375
end
8476
end

0 commit comments

Comments
 (0)