Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unit_test_failure.rb « ci « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 37893f6cdaeceba3960de2a33942bd877b8bba20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

module Ci
  class UnitTestFailure < Ci::ApplicationRecord
    include Ci::Partitionable
    include SafelyChangeColumnDefault

    columns_changing_default :partition_id

    REPORT_WINDOW = 14.days

    validates :unit_test, :build, :failed_at, presence: true

    belongs_to :unit_test, class_name: "Ci::UnitTest", foreign_key: :unit_test_id
    belongs_to :build, class_name: "Ci::Build", foreign_key: :build_id

    partitionable scope: :build

    scope :deletable, -> { where('failed_at < ?', REPORT_WINDOW.ago) }

    def self.recent_failures_count(project:, unit_test_keys:, date_range: REPORT_WINDOW.ago..Time.current)
      joins(:unit_test)
        .where(
          ci_unit_tests: {
            project_id: project.id,
            key_hash: unit_test_keys
          },
          ci_unit_test_failures: {
            failed_at: date_range
          }
        )
        .group(:key_hash)
        .count('ci_unit_test_failures.id')
    end
  end
end