Skip to content

Commit 76a83cf

Browse files
authored
Fix sentry-rails's flaky test (#1813)
* Remove debug code * Make sure the asset analyzing job happens synchronously
1 parent 905a8ba commit 76a83cf

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

sentry-rails/spec/dummy/test_rails_app/app.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def self.name
5050
app.config.secret_key_base = "test"
5151
app.config.logger = Logger.new(nil)
5252
app.config.eager_load = true
53+
app.config.active_job.queue_adapter = :test
5354

5455
configure_app(app)
5556

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,30 @@
1414
end
1515

1616
it "records the upload event" do
17+
# make sure AnalyzeJob will be executed immediately
18+
ActiveStorage::AnalyzeJob.queue_adapter.perform_enqueued_jobs = true
19+
1720
p = Post.create!
1821
get "/posts/#{p.id}/attach"
1922

2023
expect(response).to have_http_status(:ok)
21-
transport.events.each { |e| pp e } # TODO: Remove it once this test is not flaky anymore
22-
expect(transport.events.count).to eq(1)
24+
expect(transport.events.count).to eq(2)
25+
26+
analysis_transaction = transport.events.first.to_hash
27+
expect(analysis_transaction[:type]).to eq("transaction")
28+
expect(analysis_transaction[:spans].count).to eq(1)
29+
span = analysis_transaction[:spans][0]
30+
expect(span[:op]).to eq("service_streaming_download.active_storage")
2331

24-
transaction = transport.events.first.to_hash
25-
expect(transaction[:type]).to eq("transaction")
26-
expect(transaction[:spans].count).to eq(1)
32+
request_transaction = transport.events.last.to_hash
33+
expect(request_transaction[:type]).to eq("transaction")
34+
expect(request_transaction[:spans].count).to eq(1)
2735

28-
span = transaction[:spans][0]
36+
span = request_transaction[:spans][0]
2937
expect(span[:op]).to eq("service_upload.active_storage")
3038
expect(span[:description]).to eq("Disk")
3139
expect(span.dig(:data, :key)).to eq(p.cover.key)
32-
expect(span[:trace_id]).to eq(transaction.dig(:contexts, :trace, :trace_id))
40+
expect(span[:trace_id]).to eq(request_transaction.dig(:contexts, :trace, :trace_id))
3341
end
3442
end
3543

0 commit comments

Comments
 (0)