Sha256: 8ffdc03a7d37b8d43a867dc45e3da4149d37b8eff0033dad4648216c6fe9c058

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require_relative "concurrent_span"

module Datadog
  module CI
    # Represents a single test suite.
    #
    # Read here on what test suite means:
    # https://docs.datadoghq.com/continuous_integration/explorer/?tab=testruns#suite
    #
    # This object can be shared between multiple threads.
    #
    # @public_api
    class TestSuite < ConcurrentSpan
      def initialize(tracer_span)
        super

        @test_suite_stats = Hash.new(0)
      end

      # Finishes this test suite.
      # @return [void]
      def finish
        synchronize do
          # we try to derive test suite status from execution stats if no status was set explicitly
          set_status_from_stats! if undefined?

          super

          recorder.deactivate_test_suite(name)
        end
      end

      # @internal
      def record_test_result(datadog_test_status)
        synchronize do
          @test_suite_stats[datadog_test_status] += 1
        end
      end

      # @internal
      def passed_tests_count
        synchronize do
          @test_suite_stats[Ext::Test::Status::PASS]
        end
      end

      # @internal
      def skipped_tests_count
        synchronize do
          @test_suite_stats[Ext::Test::Status::SKIP]
        end
      end

      # @internal
      def failed_tests_count
        synchronize do
          @test_suite_stats[Ext::Test::Status::FAIL]
        end
      end

      private

      def set_status_from_stats!
        if failed_tests_count > 0
          failed!
        elsif passed_tests_count == 0
          skipped!
        else
          passed!
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
datadog-ci-1.0.0.beta1 lib/datadog/ci/test_suite.rb
datadog-ci-0.8.3 lib/datadog/ci/test_suite.rb
datadog-ci-0.8.2 lib/datadog/ci/test_suite.rb
datadog-ci-0.8.1 lib/datadog/ci/test_suite.rb
datadog-ci-0.8.0 lib/datadog/ci/test_suite.rb
datadog-ci-0.7.0 lib/datadog/ci/test_suite.rb