Skip to content

Commit 162ca86

Browse files
authored
More flaky spec fixes (#2670)
* Relax time expectation for jruby * Wait a bit for queue to clear for jruby
1 parent 6bd141c commit 162ca86

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@
5353
expect(second_span[:parent_span_id]).to eq(first_span[:span_id])
5454

5555
# this is to make sure we calculate the timestamp in the correct scale (second instead of millisecond)
56-
expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(10.0 / 1_000_000, 10.0 / 1000)
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)
5760
end
5861

5962
it "records transaction alone" do
@@ -89,7 +92,10 @@
8992
expect(second_span[:parent_span_id]).to eq(first_span[:span_id])
9093

9194
# this is to make sure we calculate the timestamp in the correct scale (second instead of millisecond)
92-
expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(10.0 / 1_000_000, 10.0 / 1000)
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)
9399

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

sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,26 @@ def timecop_delay
141141
# the default queue
142142
let!(:queue) { Sidekiq::Queue.new("default") }
143143

144-
before do
144+
def ensure_queue_empty(queue, timeout: 0.1)
145145
queue.clear
146+
start_time = Time.now
147+
while queue.size > 0 && (Time.now - start_time) < timeout
148+
sleep(0.001)
149+
end
150+
end
151+
152+
before do
153+
ensure_queue_empty(queue)
154+
146155
perform_basic_setup do |config|
147156
config.traces_sample_rate = 1.0
148157
end
149158
end
150159

160+
after do
161+
ensure_queue_empty(queue)
162+
end
163+
151164
it "does not add user to the job if they're absent in the current scope" do
152165
client.push('queue' => 'default', 'class' => HappyWorker, 'args' => [])
153166

0 commit comments

Comments
 (0)