judges 0.53.2 → 0.53.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa86305c49cd5701b671c3e8a6705e07971e7000ea5c327ad6db9e0aa688f4c8
4
- data.tar.gz: 9f9445c8c832b285b75d6b816127bb504e6bb3e548616c6cc999dda56dbe15c4
3
+ metadata.gz: 8ee9872053ac43a975675a9eaed91b496bdb91ba0d3dc5595f956073c5ba2a13
4
+ data.tar.gz: 67e1409f8793c1fa9ad634d732f3596ef4ff08e9d587a14dc0a8b1ce3490622c
5
5
  SHA512:
6
- metadata.gz: b07a315a2bbd216ce359b6f81b1a04993929dc58feaa315413254ef0d72335a6fca76ef1716e597b39e81c8d5cc9f4a03f2d9de365b0e614f9420425afa9c81b
7
- data.tar.gz: 9732e62b8e45b852b6eaa673a5924d61f7d6f67e0fae1f4bd76f0ecc996337236c3b52e2212a1b7efe2a31a701aae2f874f1be1bf15f814131dea9f90f4c3761
6
+ metadata.gz: ca7c356028c05c6bfdab1e6d7e826865dfe6f4e3ca5bec43718465a2ec03f39ba7823fb2fee05982e95c1ca0312003b3856f65a9e3e737d48ad3613c1afcb5b7
7
+ data.tar.gz: 692e4a5de4b92d85fcc15a22b7004dc72e5ebf83c339c34e5a8d4ac9bce08e62327f57ad1e96e50f3ddc4ce98fb149caadf567a9fe13943150fa1fda67ec667c
data/Gemfile.lock CHANGED
@@ -177,7 +177,7 @@ GEM
177
177
  tago (> 0)
178
178
  regexp_parser (2.11.2)
179
179
  retries (0.0.5)
180
- rexml (3.4.1)
180
+ rexml (3.4.2)
181
181
  rubocop (1.80.0)
182
182
  json (~> 2.3)
183
183
  language_server-protocol (~> 3.17.0.2)
@@ -208,7 +208,7 @@ GEM
208
208
  docile (~> 1.1)
209
209
  simplecov-html (~> 0.11)
210
210
  simplecov_json_formatter (~> 0.1)
211
- simplecov-cobertura (3.0.0)
211
+ simplecov-cobertura (3.1.0)
212
212
  rexml
213
213
  simplecov (~> 0.19)
214
214
  simplecov-html (0.13.2)
@@ -63,7 +63,7 @@ Feature: Update
63
63
  n.type = 'second'
64
64
  """
65
65
  Then I run bin/judges with "--verbose update --quiet --lifetime 2 --timeout 1 --max-cycles 5 . simple.fb"
66
- Then Stdout contains "Update completed in 2 cycle(s), did 1i/0d/1a"
66
+ Then Stdout contains "Update completed in 2 cycle(s), did 3i/0d/3a"
67
67
  And Exit code is zero
68
68
 
69
69
  Scenario: Use options from a file
@@ -93,7 +93,6 @@ Feature: Update
93
93
  """
94
94
  Then I run bin/judges with "--verbose update --timeout 1 --quiet . foo.fb"
95
95
  Then Stdout contains "execution expired"
96
- Then Stdout contains "judge timed out after"
97
96
  Then Stdout contains "1 judge(s) processed"
98
97
  Then Stdout contains "Update completed in 1 cycle(s), did 0i/0d/0a"
99
98
  And Exit code is zero
data/judges.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
10
  s.required_ruby_version = '>=3.2'
11
11
  s.name = 'judges'
12
- s.version = '0.53.2'
12
+ s.version = '0.53.4'
13
13
  s.license = 'MIT'
14
14
  s.summary = 'Command-Line Tool for a Factbase'
15
15
  s.description =
@@ -69,8 +69,13 @@ class Judges::Update
69
69
  start: @start, shuffle: opts['shuffle'], boost: opts['boost'],
70
70
  demote: opts['demote']
71
71
  )
72
- Timeout.timeout(opts['lifetime']) do
73
- loop_them(impex, judges, fb, opts, options)
72
+ begin
73
+ Timeout.timeout(opts['lifetime']) do
74
+ loop_them(impex, judges, fb, opts, options)
75
+ end
76
+ rescue Timeout::Error, Timeout::ExitException => e
77
+ raise e unless opts['quiet']
78
+ @loog.info("Had to stop due to the --lifetime=#{opts['lifetime']}")
74
79
  end
75
80
  end
76
81
 
@@ -215,6 +220,7 @@ class Judges::Update
215
220
  def one_judge(opts, fb, judge, global, options, errors)
216
221
  local = {}
217
222
  start = Time.now
223
+ fb = Factbase::Tallied.new(fb)
218
224
  begin
219
225
  if opts['lifetime'] && Time.now - @start > opts['lifetime']
220
226
  throw :"👎 The '#{judge.name}' judge skipped, no time left"
@@ -224,8 +230,8 @@ class Judges::Update
224
230
  end
225
231
  rescue Timeout::Error, Timeout::ExitException => e
226
232
  errors << "Judge #{judge.name} stopped by timeout after #{start.ago}: #{e.message}"
227
- throw :"👎 The '#{judge.name}' judge timed out after #{start.ago}: #{e.message}"
228
233
  end
234
+ fb.churn
229
235
  end
230
236
 
231
237
  def include?(opts, name)
data/lib/judges/judge.rb CHANGED
@@ -53,10 +53,10 @@ class Judges::Judge
53
53
  # @param [Hash] global Global configuration options shared across all judges
54
54
  # @param [Hash] local Local configuration options specific to this judge
55
55
  # @param [Judges::Options] options Command-line options object
56
- # @return [Factbase::Churn] Object containing statistics about the changes made to the factbase
56
+ # @return [nil] Nothing
57
57
  # @raise [RuntimeError] If the lib directory doesn't exist, the script can't be loaded, or execution fails
58
58
  def run(fb, global, local, options)
59
- $fb = Factbase::Tallied.new(fb)
59
+ $fb = fb
60
60
  $judge = File.basename(@dir)
61
61
  $options = options
62
62
  $loog = @loog
@@ -76,7 +76,7 @@ class Judges::Judge
76
76
  raise "Can't load '#{s}'" unless File.exist?(s)
77
77
  elapsed(@loog, good: "#{$judge} completed", level: Logger::INFO) do
78
78
  load(s, true)
79
- $fb.churn
79
+ nil
80
80
  # rubocop:disable Lint/RescueException
81
81
  rescue Exception => e
82
82
  # rubocop:enable Lint/RescueException
data/lib/judges.rb CHANGED
@@ -8,5 +8,5 @@
8
8
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
9
9
  # License:: MIT
10
10
  module Judges
11
- VERSION = '0.53.2' unless const_defined?(:VERSION)
11
+ VERSION = '0.53.4' unless const_defined?(:VERSION)
12
12
  end
@@ -39,6 +39,20 @@ class TestUpdate < Minitest::Test
39
39
  end
40
40
  end
41
41
 
42
+ def test_cancels_slow_execution
43
+ Dir.mktmpdir do |d|
44
+ 10.times do |i|
45
+ save_it(File.join(d, "foo-#{i}/foo-#{i}.rb"), '$fb.insert.foo = 0.05; sleep 2;')
46
+ end
47
+ file = File.join(d, 'base.fb')
48
+ Judges::Update.new(Loog::NULL).run({ 'lifetime' => 0.12, 'timeout' => 0.1, 'quiet' => true }, [d, file])
49
+ fb = Factbase.new
50
+ fb.import(File.binread(file))
51
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
52
+ refute_empty(xml.xpath('/fb/f[foo]'), xml)
53
+ end
54
+ end
55
+
42
56
  def test_cancels_slow_judge
43
57
  Dir.mktmpdir do |d|
44
58
  save_it(File.join(d, 'foo/foo.rb'), 'sleep 10; $fb.insert.foo = 1')
@@ -55,7 +69,28 @@ class TestUpdate < Minitest::Test
55
69
  Dir.mktmpdir do |d|
56
70
  save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.foo = 1; sleep 10')
57
71
  file = File.join(d, 'base.fb')
58
- Judges::Update.new(Loog::NULL).run({ 'timeout' => 0.1, 'quiet' => true }, [d, file])
72
+ Judges::Update.new(Loog::NULL).run(
73
+ { 'timeout' => 0.1, 'quiet' => true, 'fail-fast' => true },
74
+ [d, file]
75
+ )
76
+ fb = Factbase.new
77
+ fb.import(File.binread(file))
78
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
79
+ refute_empty(xml.xpath('/fb/f[foo]'), xml)
80
+ end
81
+ end
82
+
83
+ def test_reports_changes_from_slow_judge
84
+ Dir.mktmpdir do |d|
85
+ save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.foo = 1; sleep 10')
86
+ file = File.join(d, 'base.fb')
87
+ log = Loog::Buffer.new
88
+ Judges::Update.new(Loog::Tee.new(log, Loog::NULL)).run(
89
+ { 'timeout' => 0.1, 'quiet' => true, 'fail-fast' => true },
90
+ [d, file]
91
+ )
92
+ assert_includes(log.to_s, 'did 1i/0d/1a')
93
+ assert_includes(log.to_s, 'Update completed in 1 cycle(s), did 1i/0d/1a')
59
94
  fb = Factbase.new
60
95
  fb.import(File.binread(file))
61
96
  xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
data/test/test_judge.rb CHANGED
@@ -25,30 +25,6 @@ class TestJudge < Minitest::Test
25
25
  end
26
26
  end
27
27
 
28
- def test_counts_churn
29
- Dir.mktmpdir do |d|
30
- save_it(File.join(d, "#{File.basename(d)}.rb"), '$fb.insert.foo = 42')
31
- judge = Judges::Judge.new(d, nil, Loog::NULL)
32
- fb = Factbase.new
33
- c = judge.run(fb, {}, {}, {})
34
- assert_equal(1, c.inserted)
35
- assert_equal(0, c.deleted)
36
- assert_equal(1, c.added)
37
- end
38
- end
39
-
40
- def test_counts_churn_after_txn
41
- Dir.mktmpdir do |d|
42
- save_it(File.join(d, "#{File.basename(d)}.rb"), '$fb.txn { |fbt| fbt.insert.foo = 42 }')
43
- judge = Judges::Judge.new(d, nil, Loog::NULL)
44
- fb = Factbase.new
45
- c = judge.run(fb, {}, {}, {})
46
- assert_equal(1, c.inserted)
47
- assert_equal(0, c.deleted)
48
- assert_equal(1, c.added)
49
- end
50
- end
51
-
52
28
  def test_run_isolated
53
29
  Dir.mktmpdir do |d|
54
30
  save_it(File.join(d, "#{File.basename(d)}.rb"), '$fb.insert')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.53.2
4
+ version: 0.53.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko