Class: Datadog::CI::TestSuite

Inherits:
ConcurrentSpan show all
Defined in:
lib/datadog/ci/test_suite.rb

Overview

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.

Instance Attribute Summary

Attributes inherited from Span

#tracer_span

Instance Method Summary collapse

Methods inherited from ConcurrentSpan

#get_tag, #set_metric, #set_tag, #set_tags, #synchronize

Methods inherited from Span

#clear_tag, #failed!, #failed?, #get_metric, #get_tag, #git_branch, #git_commit_sha, #git_repository_url, #id, #name, #os_architecture, #os_platform, #os_version, #passed!, #passed?, #runtime_name, #runtime_version, #service, #set_default_tags, #set_environment_runtime_tags, #set_metric, #set_tag, #set_tags, #skipped!, #skipped?, #source_file, #to_s, #trace_id, #type, #undefined?

Constructor Details

#initialize(tracer_span) ⇒ TestSuite

Returns a new instance of TestSuite.



16
17
18
19
20
21
22
# File 'lib/datadog/ci/test_suite.rb', line 16

def initialize(tracer_span)
  super

  # counts how many times every test in this suite was executed with each status:
  #   { "MySuite.mytest.a:1" => { "pass" => 3, "fail" => 2 } }
  @execution_stats_per_test = {}
end

Instance Method Details

#any_passed?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/datadog/ci/test_suite.rb', line 46

def any_passed?
  synchronize do
    @execution_stats_per_test.any? do |_, stats|
      stats[Ext::Test::Status::PASS] > 0
    end
  end
end

#any_test_retry_passed?(test_id) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
# File 'lib/datadog/ci/test_suite.rb', line 55

def any_test_retry_passed?(test_id)
  synchronize do
    stats = @execution_stats_per_test[test_id]
    stats && stats[Ext::Test::Status::PASS] > 0
  end
end

#finishvoid

This method returns an undefined value.

Finishes this test suite.



26
27
28
29
30
31
32
33
34
35
# File 'lib/datadog/ci/test_suite.rb', line 26

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?

    test_visibility.deactivate_test_suite(name)

    super
  end
end

#record_test_result(test_id, datadog_test_status) ⇒ Object



38
39
40
41
42
43
# File 'lib/datadog/ci/test_suite.rb', line 38

def record_test_result(test_id, datadog_test_status)
  synchronize do
    @execution_stats_per_test[test_id] ||= Hash.new(0)
    @execution_stats_per_test[test_id][datadog_test_status] += 1
  end
end

#test_executed?(test_id) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
# File 'lib/datadog/ci/test_suite.rb', line 63

def test_executed?(test_id)
  synchronize do
    @execution_stats_per_test.key?(test_id)
  end
end