diff --git a/lib/datadog/ci/test_session.rb b/lib/datadog/ci/test_session.rb index 56c220ea..c6e49217 100644 --- a/lib/datadog/ci/test_session.rb +++ b/lib/datadog/ci/test_session.rb @@ -4,7 +4,7 @@ module Datadog module CI - # Represents the whole test command process. + # Represents the whole test session process. # This object can be shared between multiple threads. # # @public_api @@ -14,6 +14,14 @@ def initialize(tracer_span) @mutex = Mutex.new end + + # Finishes the current test session. + # @return [void] + def finish + super + + CI.deactivate_test_session + end end end end diff --git a/spec/datadog/ci/test_session_spec.rb b/spec/datadog/ci/test_session_spec.rb new file mode 100644 index 00000000..e2a6e148 --- /dev/null +++ b/spec/datadog/ci/test_session_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +RSpec.describe Datadog::CI::TestSession do + let(:tracer_span) { instance_double(Datadog::Tracing::SpanOperation, finish: true) } + + describe "#finish" do + subject(:ci_test_session) { described_class.new(tracer_span) } + + before { allow(Datadog::CI).to receive(:deactivate_test_session) } + + it "deactivates the test" do + ci_test_session.finish + + expect(Datadog::CI).to have_received(:deactivate_test_session) + end + end +end