Class: Debci::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/debci/status.rb

Overview

This class represents one test execution.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#architectureObject

Returns the value of attribute architecture



11
12
13
# File 'lib/debci/status.rb', line 11

def architecture
  @architecture
end

#blameObject

Returns the value of attribute blame



10
11
12
# File 'lib/debci/status.rb', line 10

def blame
  @blame
end

#dateObject

Returns the value of attribute date



11
12
13
# File 'lib/debci/status.rb', line 11

def date
  @date
end

#duration_humanObject

Returns the value of attribute duration_human



11
12
13
# File 'lib/debci/status.rb', line 11

def duration_human
  @duration_human
end

#duration_secondsObject

Returns the value of attribute duration_seconds



11
12
13
# File 'lib/debci/status.rb', line 11

def duration_seconds
  @duration_seconds
end

#last_pass_dateObject

Returns the value of attribute last_pass_date



11
12
13
# File 'lib/debci/status.rb', line 11

def last_pass_date
  @last_pass_date
end

#last_pass_versionObject

Returns the value of attribute last_pass_version



11
12
13
# File 'lib/debci/status.rb', line 11

def last_pass_version
  @last_pass_version
end

#messageObject

Returns the value of attribute message



11
12
13
# File 'lib/debci/status.rb', line 11

def message
  @message
end

#packageObject

Returns the value of attribute package



11
12
13
# File 'lib/debci/status.rb', line 11

def package
  @package
end

#previous_statusObject

Returns the value of attribute previous_status



11
12
13
# File 'lib/debci/status.rb', line 11

def previous_status
  @previous_status
end

#run_idObject

Returns the value of attribute run_id



11
12
13
# File 'lib/debci/status.rb', line 11

def run_id
  @run_id
end

#statusObject

Returns the value of attribute status



11
12
13
# File 'lib/debci/status.rb', line 11

def status
  @status
end

#suiteObject

Returns the value of attribute suite



11
12
13
# File 'lib/debci/status.rb', line 11

def suite
  @suite
end

#triggerObject

Returns the value of attribute trigger



11
12
13
# File 'lib/debci/status.rb', line 11

def trigger
  @trigger
end

#versionObject

Returns the value of attribute version



11
12
13
# File 'lib/debci/status.rb', line 11

def version
  @version
end

Class Method Details

.from_data(data, suite, architecture) ⇒ Object

Populates an object by reading from a data hash



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/debci/status.rb', line 149

def self.from_data(data, suite, architecture)
  status = Debci::Status.new

  status.suite = suite
  status.architecture = architecture
  status.run_id = data['run_id'] || data['date']
  status.package = data['package']
  status.version = data['version']
  status.date =
    begin
      Time.parse(data.fetch('date', 'unknown') + ' UTC')
    rescue ArgumentError
      nil
    end
  status.trigger = data['trigger']
  status.status = data.fetch('status', :unknown).to_sym
  status.previous_status = data.fetch('previous_status', :unknown).to_sym
  status.blame = data['blame']
  status.duration_seconds =
    begin
      Integer(data.fetch('duration_seconds', 0))
    rescue ArgumentError
      nil
    end
  status.duration_human = data['duration_human']
  status.message = data['message']
  status.last_pass_version = data.fetch('last_pass_version', 'unknown')
  status.last_pass_date =
    begin
      Time.parse(data.fetch('last_pass_date', 'unknown') + ' UTC')
    rescue ArgumentError
      nil
    end

  status
end

.from_file(file, suite, architecture) ⇒ Object

Constructs a new object by reading the JSON status file.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/debci/status.rb', line 123

def self.from_file(file, suite, architecture)
  status = new
  status.suite = suite
  status.architecture = architecture

  unless File.exists?(file)
    status.status = :no_test_data
    return status
  end

  data = nil

  begin
    File.open(file, 'r') do |f|
      data = JSON.load(f)
    end
  rescue JSON::ParserError
    true # nothing really
  end

  return status unless data

  from_data(data, suite, architecture)
end

Instance Method Details

#descriptionObject

A longer version of the headline for a new failure, include whether this version previously passed



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/debci/status.rb', line 91

def description
  msg = "The tests for #{package}, version #{version}, #{status.upcase}ED on #{suite}/#{architecture} but have previously #{previous_status.upcase}ED"
  msg += case extended_status
    when :fail_passed_current
      " for the current version."
    when :fail_passed_old
      " for version #{last_pass_version}."
    else
      "."
    end
end

#expired?Boolean

Returns:

  • (Boolean)


186
187
188
189
190
191
192
193
194
# File 'lib/debci/status.rb', line 186

def expired?
  days = Debci.config.data_retention_days.to_i
  if days > 0
    retention_window = days * (24*60*60)
    Time.now > self.date + retention_window
  else
    false
  end
end

#extended_statusObject

a larger set of possible test result states, to show “at a glance” the package's test history potentially other attributes could be included here * partial or total failure if there are multiple tests * dependency failure vs test failure * guessed nondeterminism but probably too many combinations will make this unhelpful



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/debci/status.rb', line 38

def extended_status
  case status
  when :pass
    :pass
  # distinguish between always failing, and whether the test has
  # previously passed for this or older versions
  when :fail
    case last_pass_version
    when "never"
      :fail_passed_never
    when version
      :fail_passed_current
    when "unknown"
      :fail
    else
      :fail_passed_old
    end
  # tmpfail is usually not interesting to the observer, so provide
  # a hint if it is masking a previous pass or fail
  when :tmpfail
    case previous_status
    when :pass
      :tmpfail_pass
    when :fail
      :tmpfail_fail
    else
      :tmpfail
    end
  else
    status
  end
end

#failmsgObject



71
72
73
74
75
76
77
# File 'lib/debci/status.rb', line 71

def failmsg
  {
    :fail_passed_never => "never passed",
    :fail_passed_current => "previously passed",
    :fail_passed_old => "#{last_pass_version} passed"
  }[extended_status]
end

#headlineObject

Returns a headline for this status object, to be used as a short description of the event it represents



81
82
83
84
85
86
87
# File 'lib/debci/status.rb', line 81

def headline
  msg = "#{package} #{version} #{status.upcase}ED on #{suite}/#{architecture}"
  if status == :fail && failmsg
    msg += " (#{failmsg})"
  end
  msg
end

#inspectObject



196
197
198
# File 'lib/debci/status.rb', line 196

def inspect
  "<#{suite}/#{architecture} #{status}>"
end

#newsworthy?Boolean

Returns true if this status object represents an important event, such as a package that used to pass started failing, of vice versa.

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/debci/status.rb', line 15

def newsworthy?
  [
    [:fail, :pass],
    [:pass, :fail],
  ].include?([status, previous_status])
end

#timeObject

Returns the amount of time since the date for this status object



112
113
114
115
116
117
118
119
120
# File 'lib/debci/status.rb', line 112

def time
  days = (Time.now - date)/86400

  if days >= 1 || days <= -1
    "#{days.floor} day(s) ago"
  else
    "#{Time.at(Time.now - date).gmtime.strftime('%H')} hour(s) ago"
  end
end

#titleObject



22
23
24
25
26
27
28
29
# File 'lib/debci/status.rb', line 22

def title
  {
    :pass => "Pass",
    :fail => "Fail",
    :tmpfail => "Temporary failure",
    :no_test_data => "No test data",
  }.fetch(status, "Unknown")
end