Skip to content

Commit

Permalink
more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Nov 22, 2023
1 parent b8a4c14 commit b73d971
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 32 deletions.
43 changes: 15 additions & 28 deletions lib/datadog/ci/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def trace(span_type, span_name, tags: {}, &block)
end
end

def active_span
tracer_span = Datadog::Tracing.active_span
Span.new(tracer_span) if tracer_span
end

def active_test
@local_context.active_test
end
Expand All @@ -101,13 +106,13 @@ def active_test_session
@global_context.active_test_session
end

# TODO: does it make sense to have a paramter here?
def deactivate_test(test)
@local_context.deactivate_test!(test)
end

def active_span
tracer_span = Datadog::Tracing.active_span
Span.new(tracer_span) if tracer_span
def deactivate_test_session
@global_context.deactivate_test_session!
end

private
Expand All @@ -119,46 +124,28 @@ def set_trace_origin(trace)

def build_test_session(tracer_span, tags)
test_session = TestSession.new(tracer_span)

test_session.set_default_tags
test_session.set_environment_runtime_tags

test_session.set_tags(tags)
test_session.set_tags(environment_tags)

set_initial_tags(test_session, tags)
test_session
end

def build_test(tracer_span, tags)
test = Test.new(tracer_span)

test.set_default_tags
test.set_environment_runtime_tags

test.set_tags(tags)
test.set_tags(environment_tags)

set_initial_tags(test, tags)
test
end

def build_span(tracer_span, tags)
span = Span.new(tracer_span)

span.set_default_tags
span.set_environment_runtime_tags
span.set_tags(tags)

set_initial_tags(span, tags)
span
end

def set_initial_tags(ci_span, tags)
tags.each do |key, value|
ci_span.set_default_tags
ci_span.set_environment_runtime_tags
ci_span.set_default_tags
ci_span.set_environment_runtime_tags

ci_span.set_tags(tags)
ci_span.set_tags(environment_tags)
end
ci_span.set_tags(tags)
ci_span.set_tags(environment_tags)
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions sig/datadog/ci/recorder.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module Datadog

def deactivate_test: (Datadog::CI::Test test) -> void

def deactivate_test_session: () -> void

def create_datadog_span: (String span_name, ?span_options: Hash[untyped, untyped], ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped

def set_trace_origin: (Datadog::Tracing::TraceOperation trace) -> untyped
Expand All @@ -30,6 +32,8 @@ module Datadog
def build_test_session: (Datadog::Tracing::SpanOperation tracer_span, Hash[untyped, untyped] tags) -> Datadog::CI::TestSession

def build_span: (Datadog::Tracing::SpanOperation tracer_span, Hash[untyped, untyped] tags) -> Datadog::CI::Span

def set_initial_tags: (Datadog::CI::Span ci_span, Hash[untyped, untyped] tags) -> void
end
end
end
35 changes: 31 additions & 4 deletions spec/datadog/ci/recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
end

let(:span_op) { Datadog::Tracing::SpanOperation.new(span_name) }
let(:ci_span) { instance_double(Datadog::CI::Span) }

before do
allow(Datadog::Tracing)
Expand Down Expand Up @@ -258,7 +257,6 @@
let(:session_operation_name) { "test.session" }

let(:span_op) { Datadog::Tracing::SpanOperation.new(session_operation_name) }
let(:ci_test_session) { instance_double(Datadog::CI::TestSession) }

before do
allow(Datadog::Tracing)
Expand All @@ -271,10 +269,39 @@
}
)
.and_return(span_op)

allow(Datadog::CI::TestSession).to receive(:new).with(span_op).and_return(ci_span)

start_test_session
end

it do
expect(start_test_session.tracer_span).to be(span_op)
it_behaves_like "internal tracing context"
it_behaves_like "initialize ci span with tags"

it { is_expected.to be(ci_span) }
end

describe "#active_test_session" do
subject(:active_test_session) { recorder.active_test_session }

let(:ci_session) do
recorder.start_test_session(service_name: service)
end

before { ci_session }

it { is_expected.to be(ci_session) }
end

describe "#deactivate_test_session" do
subject(:deactivate_test_session) { recorder.deactivate_test_session }

let(:ci_session) do
recorder.start_test_session(service_name: service)
end

before { deactivate_test_session }

it { expect(recorder.active_test_session).to be_nil }
end
end

0 comments on commit b73d971

Please sign in to comment.