Skip to content

Commit

Permalink
CCOL-2039: Add mock span to mock tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Pereira committed Dec 5, 2023
1 parent 1a5b7db commit ea099a3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/deimos/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def unit_test!
deimos_config.kafka.seed_brokers ||= ['test_broker']
deimos_config.schema.backend = Deimos.schema_backend_class.mock_backend
deimos_config.producers.backend = :test
deimos_config.tracer = Deimos::Tracing::Mock.new
end
end

Expand Down
29 changes: 26 additions & 3 deletions lib/deimos/tracing/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Mock < Tracing::Provider
def initialize(logger=nil)
@logger = logger || Logger.new(STDOUT)
@logger.info('MockTracingProvider initialized')
@active_span = MockSpan.new
end

# @param span_name [String]
Expand All @@ -32,18 +33,22 @@ def finish(span)

# :nodoc:
def active_span
nil
@active_span ||= MockSpan.new
end

# :nodoc:
def set_tag(tag, value, span=nil)
nil
if span
span.set_tag(tag, value)
else
@span.set_tag(tag, value)
end
end

# Get a tag from a span with the specified tag.
# @param tag [String]
def get_tag(tag)
nil
@span.get_tag(tag)
end

# :nodoc:
Expand All @@ -53,5 +58,23 @@ def set_error(span, exception)
@logger.info("Mock span '#{name}' set an error: #{exception}")
end
end

# Mock Span class
class MockSpan
# :nodoc:
def initialize
@span = {}
end

# :nodoc:
def set_tag(tag, value)
@span[tag] = value
end

# :nodoc:
def get_tag(tag)
@span[tag]
end
end
end
end
5 changes: 0 additions & 5 deletions spec/active_record_batch_consumer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class Widget < ActiveRecord::Base
consumer_class.config[:bulk_import_id_column] = :bulk_import_id # default
end

before(:each) do
allow(Deimos.config.tracer.active_span).to receive(:set_tag)
allow(Deimos.config.tracer.active_span).to receive(:get_tag).with('topic').and_return(%w(topic:mytopic))
end

around(:each) do |ex|
# Set and freeze example time
travel_to start do
Expand Down
1 change: 0 additions & 1 deletion spec/active_record_consume/mass_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
stub_const('Widget', widget_class)
stub_const('Detail', detail_class)
Widget.reset_column_information
allow(Deimos.config.tracer.active_span).to receive(:get_tag).with('topic').and_return(%w(topic:mytopic))
end

describe '#mass_update' do
Expand Down

0 comments on commit ea099a3

Please sign in to comment.