Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/fbe/repeatedly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# f.issues_found = count_issues
# # PMP might have: hours_between_checks=6
# end
def Fbe.repeatedly(area, p_every_hours, fb: Fbe.fb, judge: $judge, loog: $loog, &)
def Fbe.repeatedly(area, p_every_hours, fb: Fbe.fb, judge: $judge, loog: $loog, &) # rubocop:disable Metrics/AbcSize
raise(Fbe::Error, 'The area is nil') if area.nil?
raise(Fbe::Error, 'The p_every_hours is nil') if p_every_hours.nil?
raise(Fbe::Error, 'The fb is nil') if fb.nil?
Expand Down Expand Up @@ -61,8 +61,8 @@ def Fbe.repeatedly(area, p_every_hours, fb: Fbe.fb, judge: $judge, loog: $loog,
attrs = {}
yield(
others(fact: f, map: attrs) do |k, *rest|
next @fact.public_send(k, *rest) unless k.end_with?('=')
(@map[k[0..-2]] ||= []) << rest.first
next (@map[k[0..-2]] ||= []) << rest.first if k.end_with?('=')
(@map[k.to_s] || [@fact.public_send(k, *rest)]).first
end
)
Fbe.overwrite(f, attrs.merge('when' => Time.now), fb:)
Expand Down
44 changes: 44 additions & 0 deletions test/fbe/test_repeatedly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,48 @@ def test_prefers_the_configured_interval_over_the_daily_default
end
assert(ran, "the judge stayed idle #{hours + 1} hours later, while the interval is #{hours}, seed is #{seed}")
end

def test_reads_back_property_set_in_the_first_run
seed = Random.new_seed
count = Random.new(seed).rand(1..1_000_000)
fb = Fbe.fb(fb: Factbase.new, global: {}, options: Judges::Options.new, loog: Loog::NULL)
seen = nil
Fbe.repeatedly('качество', 'every_x_hours', fb:, judge: 'test', loog: Loog::NULL) do |f|
f.counter = count
seen = f.counter
end
assert_equal(count, seen, "value set by the block is not read back, seed #{seed}")
end

def test_reads_back_property_set_in_a_later_run
seed = Random.new_seed
count = Random.new(seed).rand(1..1_000_000)
fb = Fbe.fb(fb: Factbase.new, global: {}, options: Judges::Options.new, loog: Loog::NULL)
seen = nil
2.times do |i|
Time.stub(:now, Time.now + (i * 25 * 60 * 60)) do
Fbe.repeatedly('качество', 'every_x_hours', fb:, judge: 'test', loog: Loog::NULL) do |f|
f.counter = count + i
seen = f.counter
end
end
end
assert_equal(count + 1, seen, "value of the previous run is read back, seed #{seed}")
end

def test_reads_property_kept_from_the_previous_run
seed = Random.new_seed
name = "ïmage-#{Random.new(seed).rand(1_000_000)}"
fb = Fbe.fb(fb: Factbase.new, global: {}, options: Judges::Options.new, loog: Loog::NULL)
seen = nil
2.times do |i|
Time.stub(:now, Time.now + (i * 25 * 60 * 60)) do
Fbe.repeatedly('качество', 'every_x_hours', fb:, judge: 'test', loog: Loog::NULL) do |f|
next f.name = name if i.zero?
seen = f.name
end
end
end
assert_equal(name, seen, "property stored by the previous run is not read, seed #{seed}")
end
end
Loading