Skip to content

Commit

Permalink
Add a spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dasch committed Aug 21, 2020
1 parent 05ba58c commit 82e0b5a
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions spec/ddtrace/contrib/racecar/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,63 @@
Datadog.registry[:racecar].reset_configuration!
end

describe 'for both single and batch message processing' do
let(:payload) { { consumer_class: consumer } }

let(:span) do
spans.select { |s| s.name == Datadog::Contrib::Racecar::Ext::SPAN_CONSUME }.first
end

context 'that doesn\'t raise an error' do
it 'is expected to send a span' do
ActiveSupport::Notifications.instrument('main_loop.racecar', payload)

span.tap do |span|
expect(span).to_not be nil
expect(span.service).to eq('racecar')
expect(span.name).to eq('racecar.consume')
expect(span.resource).to eq(consumer)
expect(span.get_tag('kafka.consumer')).to eq(consumer)
expect(span).to_not have_error
end
end
end

context 'that raises an error' do
let(:error_class) { Class.new(StandardError) }

it 'is expected to send a span' do
# Emulate failure
begin
ActiveSupport::Notifications.instrument('main_loop.racecar', payload) do
raise error_class
end
rescue error_class
nil
end

span.tap do |span|
expect(span).to_not be nil
expect(span.service).to eq('racecar')
expect(span.name).to eq('racecar.consume')
expect(span.resource).to eq(consumer)
expect(span.get_tag('kafka.consumer')).to eq(consumer)
expect(span).to have_error
end
end
end

it_behaves_like 'analytics for integration' do
before { ActiveSupport::Notifications.instrument('main_loop.racecar', payload) }
let(:analytics_enabled_var) { Datadog::Contrib::Racecar::Ext::ENV_ANALYTICS_ENABLED }
let(:analytics_sample_rate_var) { Datadog::Contrib::Racecar::Ext::ENV_ANALYTICS_SAMPLE_RATE }
end

it_behaves_like 'measured span for integration', true do
before { ActiveSupport::Notifications.instrument('main_loop.racecar', payload) }
end
end

describe 'for single message processing' do
let(:topic) { 'dd_trace_test_dummy' }
let(:consumer) { 'DummyConsumer' }
Expand Down

0 comments on commit 82e0b5a

Please sign in to comment.