From 3b16692c66340dc39b4199363413c88f9cb4b9c8 Mon Sep 17 00:00:00 2001 From: Daniel Schierbeck Date: Fri, 21 Aug 2020 10:02:25 +0200 Subject: [PATCH] Add a spec --- spec/ddtrace/contrib/racecar/patcher_spec.rb | 58 ++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/spec/ddtrace/contrib/racecar/patcher_spec.rb b/spec/ddtrace/contrib/racecar/patcher_spec.rb index e59e54503b..5890c0a609 100644 --- a/spec/ddtrace/contrib/racecar/patcher_spec.rb +++ b/spec/ddtrace/contrib/racecar/patcher_spec.rb @@ -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' }