Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Jan 10, 2025
1 parent 067136f commit 73d1168
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
20 changes: 13 additions & 7 deletions spec/datadog/tracing/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def agent_receives_span_step3(previous_success)
end
end

shared_examples 'flushes traces with span events' do
shared_examples 'flushes traces with span events' do |native_span_events_support: true|
context 'a trace with span events' do
subject(:trace_with_event) do
tracer.trace('parent_span') do |span|
Expand All @@ -876,18 +876,20 @@ def agent_receives_span_step3(previous_success)
time_unix_nano: 123,
attributes: { 'key' => 'value' }
)
end.tap { try_wait_until(seconds: 2) { tracer.writer.stats[:traces_flushed] >= 1 } }
end

try_wait_until(seconds: 2) { tracer.writer.stats[:traces_flushed] >= 1 }
end

before do
allow_any_instance_of(Datadog::Core::Remote::Transport::HTTP::Negotiation::Response)
.to receive(:span_events).and_return(native_span_events_support)
.to receive(:span_events).and_return(span_events_support)

allow(encoder).to receive(:encode).and_wrap_original do |m, *args|
encoded = m.call(*args)
traces = encoder.decode(encoded)

traces = traces['traces'].first if traces.key?('traces')
traces = traces['traces'].first if traces.is_a?(Hash) # For Transport::IO

expect(traces).to have(1).item
@flushed_trace = traces.first
Expand All @@ -899,7 +901,11 @@ def agent_receives_span_step3(previous_success)
let(:flushed_trace) { @flushed_trace }

context 'with agent supporting native span events' do
let(:native_span_events_support) { true }
before do
skip 'Environment does not support native span events' unless native_span_events_support
end

let(:span_events_support) { true }

it 'flushes events using the span_events field' do
trace_with_event
Expand All @@ -918,7 +924,7 @@ def agent_receives_span_step3(previous_success)
end

context 'with agent not supporting native span events' do
let(:native_span_events_support) { false }
let(:span_events_support) { false }

it 'flushes events using the span_events field' do
trace_with_event
Expand Down Expand Up @@ -993,7 +999,7 @@ def agent_receives_span_step3(previous_success)
expect(out).to have_received(:puts)
end

it_behaves_like 'flushes traces with span events' do
it_behaves_like 'flushes traces with span events', native_span_events_support: false do
let(:encoder) { Datadog.send(:components).tracer.writer.transport.encoder }
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/datadog/tracing/span_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'json'
require 'msgpack'
require 'pp'
require 'time'

require 'datadog/core'
Expand Down Expand Up @@ -268,7 +267,7 @@
subject(:pretty_print) { PP.pp(span) }

it 'output without errors' do
Datadog::Tracing.trace('x') { |s| pp s}
Datadog::Tracing.trace('x') { |s| pp s }
# pretty_print
# expect { pretty_print }.to output.to_stdout
end
Expand Down
3 changes: 2 additions & 1 deletion spec/datadog/tracing/transport/traces_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@

allow(Datadog::Tracing::Transport::Traces::Request).to receive(:new).and_return(request)

allow_any_instance_of(Datadog::Core::Remote::Transport::HTTP::Negotiation::Response).to receive(:span_events).and_return(native_events_supported)
allow_any_instance_of(Datadog::Core::Remote::Transport::HTTP::Negotiation::Response).to receive(:span_events)
.and_return(native_events_supported)
end

context 'which returns an OK response' do
Expand Down

0 comments on commit 73d1168

Please sign in to comment.