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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tooling/rspec_flaky/flaky_example.rb')
-rw-r--r--tooling/rspec_flaky/flaky_example.rb57
1 files changed, 35 insertions, 22 deletions
diff --git a/tooling/rspec_flaky/flaky_example.rb b/tooling/rspec_flaky/flaky_example.rb
index 4f3688dbeed..299fcb567fc 100644
--- a/tooling/rspec_flaky/flaky_example.rb
+++ b/tooling/rspec_flaky/flaky_example.rb
@@ -3,38 +3,51 @@
require 'ostruct'
module RspecFlaky
+ ALLOWED_ATTRIBUTES = %i[
+ example_id
+ file
+ line
+ description
+ first_flaky_at
+ last_flaky_at
+ last_flaky_job
+ last_attempts_count
+ flaky_reports
+ ].freeze
+
# This represents a flaky RSpec example and is mainly meant to be saved in a JSON file
- class FlakyExample < OpenStruct
- def initialize(example)
- if example.respond_to?(:example_id)
- super(
- example_id: example.example_id,
- file: example.file,
- line: example.line,
- description: example.description,
- last_attempts_count: example.attempts,
- flaky_reports: 0)
- else
- super
+ class FlakyExample
+ def initialize(example_hash)
+ @attributes = {
+ first_flaky_at: Time.now,
+ last_flaky_at: Time.now,
+ last_flaky_job: nil,
+ last_attempts_count: example_hash[:attempts],
+ flaky_reports: 0
+ }.merge(example_hash.slice(*ALLOWED_ATTRIBUTES))
+
+ %i[first_flaky_at last_flaky_at].each do |attr|
+ attributes[attr] = Time.parse(attributes[attr]) if attributes[attr].is_a?(String)
end
end
def update_flakiness!(last_attempts_count: nil)
- self.first_flaky_at ||= Time.now
- self.last_flaky_at = Time.now
- self.flaky_reports += 1
- self.last_attempts_count = last_attempts_count if last_attempts_count
+ attributes[:first_flaky_at] ||= Time.now
+ attributes[:last_flaky_at] = Time.now
+ attributes[:flaky_reports] += 1
+ attributes[:last_attempts_count] = last_attempts_count if last_attempts_count
- if ENV['CI_PROJECT_URL'] && ENV['CI_JOB_ID']
- self.last_flaky_job = "#{ENV['CI_PROJECT_URL']}/-/jobs/#{ENV['CI_JOB_ID']}"
+ if ENV['CI_JOB_URL']
+ attributes[:last_flaky_job] = "#{ENV['CI_JOB_URL']}"
end
end
def to_h
- super.merge(
- first_flaky_at: first_flaky_at,
- last_flaky_at: last_flaky_at,
- last_flaky_job: last_flaky_job)
+ attributes.dup
end
+
+ private
+
+ attr_reader :attributes
end
end