diff --git a/spec/datadog/di/integration/instrumentation_integration_test_class.rb b/spec/datadog/di/integration/instrumentation_integration_test_class.rb index 00b4d780776..0c9630e611e 100644 --- a/spec/datadog/di/integration/instrumentation_integration_test_class.rb +++ b/spec/datadog/di/integration/instrumentation_integration_test_class.rb @@ -17,6 +17,15 @@ def test_method_with_block end # line 17 end -end # line 20 + def test_method_with_conditional + if false + a = 1 + else # line 23 + a = 2 + end # line 25 + a + end + +end # line 29 -# Comment - line 22 +# Comment - line 31 diff --git a/spec/datadog/di/integration/instrumentation_spec.rb b/spec/datadog/di/integration/instrumentation_spec.rb index 2006c9ba49a..266398115e6 100644 --- a/spec/datadog/di/integration/instrumentation_spec.rb +++ b/spec/datadog/di/integration/instrumentation_spec.rb @@ -408,10 +408,49 @@ def run_test end end + shared_examples 'installs but does not invoke probe' do + it 'installs but does not invoke probe' do + expect(component.transport).to receive(:send_request).once + probe_manager.add_probe(probe) + component.probe_notifier_worker.flush + expect(probe_manager.installed_probes.length).to eq 1 + expect(component.probe_notifier_worker).not_to receive(:add_snapshot) + call_target + end + end + + context 'target line is else of a conditional' do + let(:probe) do + Datadog::DI::Probe.new(id: "1234", type: :log, + file: 'instrumentation_integration_test_class.rb', line_no: 23, + capture_snapshot: false,) + end + + let(:call_target) do + expect(InstrumentationIntegrationTestClass.new.test_method_with_conditional).to eq(2) + end + + include_examples 'installs but does not invoke probe' + end + + context 'target line is end of a conditional' do + let(:probe) do + Datadog::DI::Probe.new(id: "1234", type: :log, + file: 'instrumentation_integration_test_class.rb', line_no: 25, + capture_snapshot: false,) + end + + let(:call_target) do + expect(InstrumentationIntegrationTestClass.new.test_method_with_conditional).to eq(2) + end + + include_examples 'installs but does not invoke probe' + end + context 'target line contains a comment (no executable code)' do let(:probe) do Datadog::DI::Probe.new(id: "1234", type: :log, - file: 'instrumentation_integration_test_class.rb', line_no: 22, + file: 'instrumentation_integration_test_class.rb', line_no: 31, capture_snapshot: false,) end