Class: GitlabQuality::TestTooling::KnapsackReports::SpecRunTime

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb

Constant Summary collapse

ACTUAL_TO_EXPECTED_SPEC_RUN_TIME_RATIO_THRESHOLD =

actual run time is longer than expected by 50% +

1.5
SPEC_WEIGHT_PERCENTAGE_TRESHOLD =

a spec file takes 15%+ of the total test suite run time

15
SUITE_DURATION_THRESHOLD =

if test suite takes more than 70 minutes, job risks timing out

70 * 60
FEATURE_CATEGORY_METADATA_REGEX =
/(?<=feature_category: :)(?<feature_category>\w+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, expected:, actual:, expected_suite_duration:, actual_suite_duration:, token: '', project: Runtime::Env.ci_project_path, ref: Runtime::Env.ci_commit_ref_name) ⇒ SpecRunTime

Returns a new instance of SpecRunTime.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 14

def initialize(
  file:,
  expected:,
  actual:,
  expected_suite_duration:,
  actual_suite_duration:,
  token: '',
  project: Runtime::Env.ci_project_path,
  ref: Runtime::Env.ci_commit_ref_name)
  @file = file
  @expected = expected.to_f
  @actual = actual.to_f
  @expected_suite_duration = expected_suite_duration.to_f
  @actual_suite_duration = actual_suite_duration.to_f
  @token = token
  @project = project
  @ref = ref
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



7
8
9
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 7

def actual
  @actual
end

#actual_suite_durationObject (readonly)

Returns the value of attribute actual_suite_duration.



7
8
9
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 7

def actual_suite_duration
  @actual_suite_duration
end

#expectedObject (readonly)

Returns the value of attribute expected.



7
8
9
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 7

def expected
  @expected
end

#expected_suite_durationObject (readonly)

Returns the value of attribute expected_suite_duration.



7
8
9
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 7

def expected_suite_duration
  @expected_suite_duration
end

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 7

def file
  @file
end

#projectObject (readonly)

Returns the value of attribute project.



7
8
9
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 7

def project
  @project
end

#refObject (readonly)

Returns the value of attribute ref.



7
8
9
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 7

def ref
  @ref
end

Instance Method Details

#actual_percentageObject



63
64
65
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 63

def actual_percentage
  (actual / actual_suite_duration * 100).round(2)
end


55
56
57
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 55

def ci_job_link_markdown
  "[#{ci_job_name}](#{ci_job_url})"
end

#ci_pipeline_created_atObject



51
52
53
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 51

def ci_pipeline_created_at
  ENV.fetch('CI_PIPELINE_CREATED_AT', nil)
end

#ci_pipeline_url_markdownObject



47
48
49
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 47

def ci_pipeline_url_markdown
  "[#{ci_pipeline_id}](#{ci_pipeline_url})"
end

#feature_categoryObject



33
34
35
36
37
38
39
40
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 33

def feature_category
  file_lines.each do |line|
    match = FEATURE_CATEGORY_METADATA_REGEX.match(line)
    next unless match

    break match[:feature_category]
  end
end


59
60
61
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 59

def file_link_markdown
  "[#{file}](#{file_link})"
end

#nameObject



67
68
69
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 67

def name
  nil
end

#should_report?Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/gitlab_quality/test_tooling/knapsack_reports/spec_run_time.rb', line 42

def should_report?
  # guideline proposed in https://gitlab.com/gitlab-org/quality/engineering-productivity/team/-/issues/354
  exceed_actual_to_expected_ratio_threshold? && test_suite_bottleneck?
end