From 82e0b5ae6a55a450d6b3fbefd8a3b90a440b47c0 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 | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/spec/ddtrace/contrib/racecar/patcher_spec.rb b/spec/ddtrace/contrib/racecar/patcher_spec.rb index e59e54503b..9affd042f8 100644 --- a/spec/ddtrace/contrib/racecar/patcher_spec.rb +++ b/spec/ddtrace/contrib/racecar/patcher_spec.rb @@ -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' }