Class: Datadog::CI::TestVisibility::KnownTests

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/test_visibility/known_tests.rb

Overview

fetches and stores a list of known tests from the backend

Defined Under Namespace

Classes: Response

Instance Method Summary collapse

Constructor Details

#initialize(dd_env:, api: nil, config_tags: {}) ⇒ KnownTests



86
87
88
89
90
# File 'lib/datadog/ci/test_visibility/known_tests.rb', line 86

def initialize(dd_env:, api: nil, config_tags: {})
  @api = api
  @dd_env = dd_env
  @config_tags = config_tags
end

Instance Method Details

#fetch(test_session) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/datadog/ci/test_visibility/known_tests.rb', line 92

def fetch(test_session)
  api = @api
  return Set.new unless api

  result = Set.new
  page_state = nil
  page_number = 1

  loop do
    Datadog.logger.debug { "Fetching known tests page ##{page_number}#{" with cursor" if page_state}" }

    response = fetch_page(api, test_session, page_state: page_state)

    unless response.ok?
      Datadog.logger.debug(
        "Failed to fetch known tests page ##{page_number}, bailing out of known tests fetch. " \
        "Early flake detection will not work."
      )
      return Set.new
    end

    page_tests = response.tests
    result.merge(page_tests)
    Datadog.logger.debug { "Received #{page_tests.size} known tests from page ##{page_number} (total so far: #{result.size})" }

    unless response.has_next?
      Datadog.logger.debug { "Stopping known tests fetch: no more pages after page ##{page_number}" }
      break
    end

    page_state = response.cursor
    page_number += 1
  end

  Datadog.logger.debug { "Finished fetching known tests: #{result.size} tests total from #{page_number} page(s)" }
  result
end