Skip to content

Commit

Permalink
rename Recorder.trace to Recorder.trace_test
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Oct 30, 2023
1 parent fd0a7a0 commit 9229867
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 124 deletions.
6 changes: 3 additions & 3 deletions lib/datadog/ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def trace_test(test_name, test_suite, service_name, operation_name, tags = {})
tags[:span_options] = span_options

if block_given?
Recorder.trace(operation_name, tags) do |span|
Recorder.trace_test(operation_name, tags) do |span|
yield Test.new(span)
end
else
tracer_span = Recorder.trace(operation_name, tags)
tracer_span = Recorder.trace_test(operation_name, tags)
Test.new(tracer_span)
end
end
Expand All @@ -43,7 +43,7 @@ def trace(span_type, span_name, span_options = {})
yield Span.new(tracer_span)
end
else
tracer_span = ::Datadog::Tracing.trace(span_name, **span_options)
tracer_span = Datadog::Tracing.trace(span_name, **span_options)
Span.new(tracer_span)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module CI
# Common behavior for CI tests
module Recorder
# Creates a new span for a CI test
def self.trace(span_name, options = {})
def self.trace_test(span_name, options = {})
span_options = {
span_type: Ext::AppTypes::TYPE_TEST
}.merge(options[:span_options] || {})
Expand Down
221 changes: 112 additions & 109 deletions spec/datadog/ci/recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
let(:options) { {} }

context "when given a block" do
subject(:trace) { described_class.trace(span_name, options, &block) }
subject(:trace) { described_class.trace_test(span_name, options, &block) }
let(:span_op) { Datadog::Tracing::SpanOperation.new(span_name) }
let(:block) { proc { |s| block_spy.call(s) } }
let(:block_result) { double("result") }
Expand All @@ -64,7 +64,7 @@
end

context "when not given a block" do
subject(:trace) { described_class.trace(span_name, options) }
subject(:trace) { described_class.trace_test(span_name, options) }
let(:span_op) { Datadog::Tracing::SpanOperation.new(span_name) }

before do
Expand Down Expand Up @@ -246,111 +246,114 @@
end
end

describe "::passed!" do
subject(:passed!) { described_class.passed!(span_op) }
let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) }

before do
allow(span_op).to receive(:set_tag)
passed!
end

it do
expect(span_op)
.to have_received(:set_tag)
.with(
Datadog::CI::Ext::Test::TAG_STATUS,
Datadog::CI::Ext::Test::Status::PASS
)
end
end

describe "::failed!" do
let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) }

before do
allow(span_op).to receive(:status=)
allow(span_op).to receive(:set_tag)
allow(span_op).to receive(:set_error)
failed!
end

shared_examples "failed test span operation" do
it do
expect(span_op)
.to have_received(:status=)
.with(1)
end

it do
expect(span_op)
.to have_received(:set_tag)
.with(
Datadog::CI::Ext::Test::TAG_STATUS,
Datadog::CI::Ext::Test::Status::FAIL
)
end
end

context "when no exception is given" do
subject(:failed!) { described_class.failed!(span_op) }

it_behaves_like "failed test span operation"
it { expect(span_op).to_not have_received(:set_error) }
end

context "when exception is given" do
subject(:failed!) { described_class.failed!(span_op, exception) }
let(:exception) { instance_double(StandardError) }

it_behaves_like "failed test span operation"

it do
expect(span_op)
.to have_received(:set_error)
.with(exception)
end
end
end

describe "::skipped!" do
let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) }

before do
allow(span_op).to receive(:set_tag)
allow(span_op).to receive(:set_error)
skipped!
end

shared_examples "skipped test span operation" do
it do
expect(span_op)
.to have_received(:set_tag)
.with(
Datadog::CI::Ext::Test::TAG_STATUS,
Datadog::CI::Ext::Test::Status::SKIP
)
end
end

context "when no exception is given" do
subject(:skipped!) { described_class.skipped!(span_op) }

it_behaves_like "skipped test span operation"
it { expect(span_op).to_not have_received(:set_error) }
end

context "when exception is given" do
subject(:skipped!) { described_class.skipped!(span_op, exception) }
let(:exception) { instance_double(StandardError) }

it_behaves_like "skipped test span operation"

it do
expect(span_op)
.to have_received(:set_error)
.with(exception)
end
end
end
# TODO: move to Span
# describe "::passed!" do
# subject(:passed!) { described_class.passed!(span_op) }
# let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) }

# before do
# allow(span_op).to receive(:set_tag)
# passed!
# end

# it do
# expect(span_op)
# .to have_received(:set_tag)
# .with(
# Datadog::CI::Ext::Test::TAG_STATUS,
# Datadog::CI::Ext::Test::Status::PASS
# )
# end
# end

# TODO: move to Span
# describe "::failed!" do
# let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) }

# before do
# allow(span_op).to receive(:status=)
# allow(span_op).to receive(:set_tag)
# allow(span_op).to receive(:set_error)
# failed!
# end

# shared_examples "failed test span operation" do
# it do
# expect(span_op)
# .to have_received(:status=)
# .with(1)
# end

# it do
# expect(span_op)
# .to have_received(:set_tag)
# .with(
# Datadog::CI::Ext::Test::TAG_STATUS,
# Datadog::CI::Ext::Test::Status::FAIL
# )
# end
# end

# context "when no exception is given" do
# subject(:failed!) { described_class.failed!(span_op) }

# it_behaves_like "failed test span operation"
# it { expect(span_op).to_not have_received(:set_error) }
# end

# context "when exception is given" do
# subject(:failed!) { described_class.failed!(span_op, exception) }
# let(:exception) { instance_double(StandardError) }

# it_behaves_like "failed test span operation"

# it do
# expect(span_op)
# .to have_received(:set_error)
# .with(exception)
# end
# end
# end

# TODO: move to Span
# describe "::skipped!" do
# let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) }

# before do
# allow(span_op).to receive(:set_tag)
# allow(span_op).to receive(:set_error)
# skipped!
# end

# shared_examples "skipped test span operation" do
# it do
# expect(span_op)
# .to have_received(:set_tag)
# .with(
# Datadog::CI::Ext::Test::TAG_STATUS,
# Datadog::CI::Ext::Test::Status::SKIP
# )
# end
# end

# context "when no exception is given" do
# subject(:skipped!) { described_class.skipped!(span_op) }

# it_behaves_like "skipped test span operation"
# it { expect(span_op).to_not have_received(:set_error) }
# end

# context "when exception is given" do
# subject(:skipped!) { described_class.skipped!(span_op, exception) }
# let(:exception) { instance_double(StandardError) }

# it_behaves_like "skipped test span operation"

# it do
# expect(span_op)
# .to have_received(:set_error)
# .with(exception)
# end
# end
# end
end
19 changes: 8 additions & 11 deletions spec/support/tracer_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@ def produce_test_trace(
)
Timecop.freeze(start_time)

Datadog::CI::Recorder.trace(
Datadog::CI.trace_test(
test_name,
test_suite,
service,
operation,
{
span_options: {
resource: test_name,
service: service
},
framework: framework,
framework_version: "1.0.0",
test_name: test_name,
test_suite: test_suite,
test_type: "test"
}
) do |span|
) do |test|
if with_http_span
Datadog::Tracing.trace("http-call", type: "http", service: "net-http") do |span, trace|
span.set_tag("custom_tag", "custom_tag_value")
Expand All @@ -48,11 +45,11 @@ def produce_test_trace(

case result
when "FAILED"
Datadog::CI::Recorder.failed!(span, exception)
test.failed!(exception)
when "SKIPPED"
Datadog::CI::Recorder.skipped!(span, exception)
test.skipped!(exception)
else
Datadog::CI::Recorder.passed!(span)
test.passed!
end

Timecop.travel(start_time + duration_seconds)
Expand Down

0 comments on commit 9229867

Please sign in to comment.