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 3b16692
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 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,64 @@
Datadog.registry[:racecar].reset_configuration!
end

describe 'for both single and batch message processing' do
let(:consumer) { 'DummyConsumer' }
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 3b16692

Please sign in to comment.