diff --git a/sentry-rails/spec/sentry/rails/tracing_spec.rb b/sentry-rails/spec/sentry/rails/tracing_spec.rb index 158a7f79e..629f78aa9 100644 --- a/sentry-rails/spec/sentry/rails/tracing_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing_spec.rb @@ -53,7 +53,10 @@ expect(second_span[:parent_span_id]).to eq(first_span[:span_id]) # this is to make sure we calculate the timestamp in the correct scale (second instead of millisecond) - expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(10.0 / 1_000_000, 10.0 / 1000) + # Use more relaxed bounds for JRuby compatibility + min_duration = 10.0 / 1_000_000 # 10 microseconds + max_duration = RUBY_PLATFORM == "java" ? 50.0 / 1000 : 10.0 / 1000 # 50ms for JRuby, 10ms for others + expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(min_duration, max_duration) end it "records transaction alone" do @@ -89,7 +92,10 @@ expect(second_span[:parent_span_id]).to eq(first_span[:span_id]) # this is to make sure we calculate the timestamp in the correct scale (second instead of millisecond) - expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(10.0 / 1_000_000, 10.0 / 1000) + # Use more relaxed bounds for JRuby compatibility + min_duration = 10.0 / 1_000_000 # 10 microseconds + max_duration = RUBY_PLATFORM == "java" ? 50.0 / 1000 : 10.0 / 1000 # 50ms for JRuby, 10ms for others + expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(min_duration, max_duration) third_span = transaction[:spans][2] expect(third_span[:op]).to eq("template.render_template.action_view") diff --git a/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb b/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb index d4dd049a1..c37580d57 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb @@ -141,13 +141,26 @@ def timecop_delay # the default queue let!(:queue) { Sidekiq::Queue.new("default") } - before do + def ensure_queue_empty(queue, timeout: 0.1) queue.clear + start_time = Time.now + while queue.size > 0 && (Time.now - start_time) < timeout + sleep(0.001) + end + end + + before do + ensure_queue_empty(queue) + perform_basic_setup do |config| config.traces_sample_rate = 1.0 end end + after do + ensure_queue_empty(queue) + end + it "does not add user to the job if they're absent in the current scope" do client.push('queue' => 'default', 'class' => HappyWorker, 'args' => [])