Class: QaServer::ScenarioRunHistory

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/qa_server/scenario_run_history.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

GOOD_MARKER =
''
BAD_MARKER =
'X'
UNKNOWN_MARKER =
'?'

Class Method Summary collapse

Class Method Details

.historical_summaryObject

Get a summary of the number of days passing/failing for scenario runs during configured time period

Examples:

auth_name, failing, passing

{ 'agrovoc' => { good: 31, bad: 2 },
  'geonames_ld4l_cache' => { good: 32, bad: 1 } }


89
90
91
92
93
94
95
96
97
98
# File 'app/models/qa_server/scenario_run_history.rb', line 89

def historical_summary
  days_good = count_days(:good)
  days_bad = count_days(:bad)
  days_unknown = count_days(:unknown)
  keys = (days_good.keys + days_bad.keys + days_unknown.keys).uniq.sort
  keys.each_with_object({}) do |auth, hash|
    next unless active_authority? auth
    hash[auth] = { good: day_count(auth, days_good), bad: day_count(auth, days_bad) + day_count(auth, days_unknown) }
  end
end

.run_failures(run_id:) ⇒ Object

Get set of failures for a run, if any.

Examples:

[ { status: :bad,
    authority_name: "geonames_ld4l_cache",
    subauthority_name: "area",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/geonames_ld4l_cache/area?q=France&maxRecords=4",
    err_message: "Unable to connect to authority",
    scenario_type: :connection
    run_time: 11.2 },
  { status: :unknown,
    authority_name: "oclcfast_ld4l_cache",
    subauthority_name: "Person",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/oclcfast_ld4l_cache/person?q=mark twain&maxRecords=4",
    err_message: "Not enough search results returned",
    scenario_type: :connection
    run_time: 0.123 } ]

Parameters:

  • run_id (Integer)

    the run on which to gather statistics



79
80
81
82
# File 'app/models/qa_server/scenario_run_history.rb', line 79

def run_failures(run_id:)
  return [] unless run_id
  QaServer::ScenarioRunHistory.where(scenario_run_registry_id: run_id).where.not(status: :good).to_a
end

.run_summary(scenario_run:) ⇒ Object

Get a summary of passing/failing tests for a run.

Examples:

ScenarioRunSummary includes methods for accessing

* run_id           [Integer] e.g. 14
* run_dt_stamp     [ActiveSupport::TimeWithZone] e.g. Wed, 19 Feb 2020 16:01:07 UTC +00:00
* authority_count  [Integer] e.g. 22
* failing_authority_count [Integer] e.g. 1
* passing_scenario_count  [Integer] e.g. 156
* failing_scenario_count  [Integer] e.g. 3
* total_scenario_count    [Integer] e.g. 159

Parameters:



47
48
49
50
51
52
53
54
55
# File 'app/models/qa_server/scenario_run_history.rb', line 47

def run_summary(scenario_run:)
  status = status_counts_in_run(run_id: scenario_run.id)
  summary_class.new(run_id: scenario_run.id,
                    run_dt_stamp: scenario_run.dt_stamp,
                    authority_count: authorities_in_run(run_id: scenario_run.id).count,
                    failing_authority_count: authorities_with_failures_in_run(run_id: scenario_run.id).count,
                    passing_scenario_count: status['good'],
                    failing_scenario_count: status['bad'] + status['unknown'])
end

.save_result(run_id:, scenario_result:) ⇒ Object

Save a scenario result

Parameters:

  • run_id (Integer)

    the run on which to gather statistics

  • result (Hash)

    the scenario result to be saved



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/qa_server/scenario_run_history.rb', line 22

def save_result(run_id:, scenario_result:)
  registry = QaServer::ScenarioRunRegistry.find(run_id)
  QaServer::ScenarioRunHistory.create(scenario_run_registry_id: run_id,
                                      status: scenario_result[:status],
                                      authority_name: scenario_result[:authority_name],
                                      subauthority_name: scenario_result[:subauthority_name],
                                      service: scenario_result[:service],
                                      action: scenario_result[:action],
                                      url: scenario_result[:url],
                                      err_message: scenario_result[:err_message],
                                      run_time: scenario_result[:run_time],
                                      date: registry.dt_stamp.to_date)
end