Class: Ci::TestFailureHistoryService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ci/test_failure_history_service.rb

Defined Under Namespace

Classes: Async

Constant Summary collapse

MAX_TRACKABLE_FAILURES =
200

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline) ⇒ TestFailureHistoryService

Returns a new instance of TestFailureHistoryService.


23
24
25
# File 'app/services/ci/test_failure_history_service.rb', line 23

def initialize(pipeline)
  @pipeline = pipeline
end

Instance Attribute Details

#pipelineObject (readonly)

Returns the value of attribute pipeline.


19
20
21
# File 'app/services/ci/test_failure_history_service.rb', line 19

def pipeline
  @pipeline
end

Instance Method Details

#asyncObject


44
45
46
# File 'app/services/ci/test_failure_history_service.rb', line 44

def async
  Async.new(self)
end

#executeObject


27
28
29
30
31
# File 'app/services/ci/test_failure_history_service.rb', line 27

def execute
  return unless should_track_failures?

  track_failures
end

#should_track_failures?Boolean

Returns:

  • (Boolean)

33
34
35
36
37
38
39
40
41
42
# File 'app/services/ci/test_failure_history_service.rb', line 33

def should_track_failures?
  return false unless project.default_branch_or_main == pipeline.ref

  # We fetch for up to MAX_TRACKABLE_FAILURES + 1 builds. So if ever we get
  # 201 total number of builds with the assumption that each job has at least
  # 1 failed unit test, then we have at least 201 failed unit tests which exceeds
  # the MAX_TRACKABLE_FAILURES of 200. If this is the case, let's early exit so we
  # don't have to parse each JUnit report of each of the 201 builds.
  failed_builds.length <= MAX_TRACKABLE_FAILURES
end