Skip to content

Commit a1f02d6

Browse files
solnicclaude
andauthored
chore(tests): spec stability fixes (#2960)
* fix(rails): make db span scale assertion flake-proof Replace the flaky timing window with the span-containment invariant: a child span cannot outlast its enclosing transaction. Catches a seconds vs milliseconds scale regression without depending on CI query timing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore(rails): skip unstable active storage spec on jruby --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1e5ad01 commit a1f02d6

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
require "spec_helper"
44

5-
RSpec.describe Sentry::Rails::Tracing::ActiveStorageSubscriber, :subscriber, type: :request, skip: Rails.version.to_f <= 5.2 do
5+
# Skipped on JRuby because it's very flaky there due to shelling out to use imagemagick CLI
6+
RSpec.describe Sentry::Rails::Tracing::ActiveStorageSubscriber, :subscriber, type: :request,
7+
skip: Rails.version.to_f <= 5.2 || RUBY_PLATFORM == "java" do
68
let(:transport) do
79
Sentry.get_current_client.transport
810
end

sentry-rails/spec/sentry/rails/tracing_spec.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@
5252
expect(second_span[:description]).to eq("SELECT \"posts\".* FROM \"posts\"")
5353
expect(second_span[:parent_span_id]).to eq(first_span[:span_id])
5454

55-
# this is to make sure we calculate the timestamp in the correct scale (second instead of millisecond)
56-
# Use more relaxed bounds for JRuby compatibility
57-
min_duration = 10.0 / 1_000_000 # 10 microseconds
58-
max_duration = RUBY_PLATFORM == "java" ? 50.0 / 1000 : 10.0 / 1000 # 50ms for JRuby, 10ms for others
59-
expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(min_duration, max_duration)
55+
expect(second_span[:timestamp] - second_span[:start_timestamp]).to be > 0
56+
expect(second_span[:start_timestamp]).to be >= transaction[:start_timestamp]
57+
expect(second_span[:timestamp]).to be <= transaction[:timestamp]
6058
end
6159

6260
it "records transaction alone" do
@@ -91,11 +89,9 @@
9189
)
9290
expect(second_span[:parent_span_id]).to eq(first_span[:span_id])
9391

94-
# this is to make sure we calculate the timestamp in the correct scale (second instead of millisecond)
95-
# Use more relaxed bounds for JRuby compatibility
96-
min_duration = 10.0 / 1_000_000 # 10 microseconds
97-
max_duration = RUBY_PLATFORM == "java" ? 50.0 / 1000 : 10.0 / 1000 # 50ms for JRuby, 10ms for others
98-
expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(min_duration, max_duration)
92+
expect(second_span[:timestamp] - second_span[:start_timestamp]).to be > 0
93+
expect(second_span[:start_timestamp]).to be >= transaction[:start_timestamp]
94+
expect(second_span[:timestamp]).to be <= transaction[:timestamp]
9995

10096
third_span = transaction[:spans][2]
10197
expect(third_span[:op]).to eq("template.render_template.action_view")

0 commit comments

Comments
 (0)