judges 0.53.0 ā 0.53.1
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 +4 -4
- data/features/update.feature +3 -4
- data/judges.gemspec +1 -1
- data/lib/judges/commands/update.rb +20 -14
- data/lib/judges/options.rb +8 -3
- data/lib/judges.rb +1 -1
- data/test/commands/test_update.rb +12 -0
- data/test/test_options.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60345e60cca92c8891851f29e255831796747e5451a14934538f52c764c3322e
|
4
|
+
data.tar.gz: 27ecf7b216dc3a1f66267168b8bd77c76531067246716765ee3158f6cd1ae00e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87e466051c31be7106a95670c4508789fac2a790627135e26afeef970306c3e7f9762e20c13641277048929e0e8f430343427da49dac387d5a2f09e9f0cde625
|
7
|
+
data.tar.gz: 9aa334a66a192dc65a1e6f7533d6a539c91c72dcbcb7506a0d85ccd01065d7446d58abdd0174dc15c428079078914bf67f08b5aa43a0222155653f82c643799f
|
data/features/update.feature
CHANGED
@@ -55,16 +55,15 @@ Feature: Update
|
|
55
55
|
"""
|
56
56
|
n = $fb.insert
|
57
57
|
n.type = 'first'
|
58
|
-
sleep
|
58
|
+
sleep 0.9
|
59
59
|
"""
|
60
60
|
Then I have a "second/second.rb" file with content:
|
61
61
|
"""
|
62
62
|
n = $fb.insert
|
63
63
|
n.type = 'second'
|
64
64
|
"""
|
65
|
-
Then I run bin/judges with "--verbose update --
|
66
|
-
Then Stdout contains "
|
67
|
-
Then Stdout contains "Update completed in 1 cycle(s), did 1i/0d/1a"
|
65
|
+
Then I run bin/judges with "--verbose update --lifetime 1 --max-cycles 5 . simple.fb"
|
66
|
+
Then Stdout contains "Update completed in 1 cycle(s), did 2i/0d/2a"
|
68
67
|
And Exit code is zero
|
69
68
|
|
70
69
|
Scenario: Use options from a file
|
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.
|
12
|
+
s.version = '0.53.1'
|
13
13
|
s.license = 'MIT'
|
14
14
|
s.summary = 'Command-Line Tool for a Factbase'
|
15
15
|
s.description =
|
@@ -42,7 +42,6 @@ class Judges::Update
|
|
42
42
|
raise 'Exactly two arguments required' unless args.size == 2
|
43
43
|
dir = args[0]
|
44
44
|
raise "The directory is absent: #{dir.to_rel}" unless File.exist?(dir)
|
45
|
-
start = Time.now
|
46
45
|
impex = Judges::Impex.new(@loog, args[1])
|
47
46
|
fb = impex.import(strict: false)
|
48
47
|
fb = Factbase::Logged.new(fb, @loog) if opts['log']
|
@@ -62,8 +61,19 @@ class Judges::Update
|
|
62
61
|
else
|
63
62
|
@loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
|
64
63
|
end
|
65
|
-
judges = Judges::Judges.new(
|
66
|
-
|
64
|
+
judges = Judges::Judges.new(
|
65
|
+
dir, opts['lib'], @loog,
|
66
|
+
start: @start, shuffle: opts['shuffle'], boost: opts['boost'],
|
67
|
+
demote: opts['demote']
|
68
|
+
)
|
69
|
+
Timeout.timeout(opts['lifetime']) do
|
70
|
+
loop_them(impex, judges, fb, opts, options)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def loop_them(impex, judges, fb, opts, options)
|
67
77
|
c = 0
|
68
78
|
churn = Factbase::Churn.new
|
69
79
|
errors = []
|
@@ -80,14 +90,14 @@ class Judges::Update
|
|
80
90
|
loop do
|
81
91
|
c += 1
|
82
92
|
if c > 1
|
83
|
-
if opts['lifetime'] && Time.now - @start > opts['lifetime']
|
93
|
+
if opts['lifetime'] && Time.now - @start > opts['lifetime'] * 0.51
|
84
94
|
@loog.info("Not starting cycle ##{c}, no time left")
|
85
95
|
c -= 1
|
86
96
|
break
|
87
97
|
end
|
88
98
|
@loog.info("\nStarting cycle ##{c}#{" (out of #{opts['max-cycles']})" if opts['max-cycles']}...")
|
89
99
|
end
|
90
|
-
delta = cycle(opts, judges, fb, options,
|
100
|
+
delta = cycle(opts, judges, fb, options, errors)
|
91
101
|
churn += delta
|
92
102
|
impex.export(fb)
|
93
103
|
if delta.zero?
|
@@ -107,26 +117,23 @@ class Judges::Update
|
|
107
117
|
throw :"š Update completed in #{c} cycle(s), did #{churn}"
|
108
118
|
end
|
109
119
|
return unless %w[add append].include?(opts['summary'])
|
110
|
-
summarize(fb, churn, errors,
|
120
|
+
summarize(fb, churn, errors, c)
|
111
121
|
impex.export(fb)
|
112
122
|
end
|
113
123
|
|
114
|
-
private
|
115
|
-
|
116
124
|
# Update the summary.
|
117
125
|
# @param [Factbase] fb The factbase
|
118
126
|
# @param [Churn] churn The churn
|
119
127
|
# @param [Array<String>] errors List of errors
|
120
|
-
# @param [Time] start When we started
|
121
128
|
# @param [Integer] cycles How many cycles
|
122
|
-
def summarize(fb, churn, errors,
|
129
|
+
def summarize(fb, churn, errors, cycles)
|
123
130
|
before = fb.query('(eq what "judges-summary")').each.to_a
|
124
131
|
if before.empty?
|
125
132
|
s = fb.insert
|
126
133
|
s.what = 'judges-summary'
|
127
134
|
s.when = Time.now
|
128
135
|
s.version = Judges::VERSION
|
129
|
-
s.seconds = Time.now - start
|
136
|
+
s.seconds = Time.now - @start
|
130
137
|
s.cycles = cycles
|
131
138
|
s.inserted = churn.inserted.size
|
132
139
|
s.deleted = churn.deleted.size
|
@@ -153,10 +160,9 @@ class Judges::Update
|
|
153
160
|
# @param [Judges::Judges] judges The judges
|
154
161
|
# @param [Factbase] fb The factbase
|
155
162
|
# @param [Judges::Options] options The options
|
156
|
-
# @param [Float] start When we started
|
157
163
|
# @param [Array<String>] errors List of errors
|
158
164
|
# @return [Factbase::Churn] How many modifications have been made
|
159
|
-
def cycle(opts, judges, fb, options,
|
165
|
+
def cycle(opts, judges, fb, options, errors)
|
160
166
|
churn = Factbase::Churn.new
|
161
167
|
global = {}
|
162
168
|
used = 0
|
@@ -168,7 +174,7 @@ class Judges::Update
|
|
168
174
|
next
|
169
175
|
end
|
170
176
|
next unless include?(opts, judge.name)
|
171
|
-
@loog.info("\nš Running #{judge.name} (##{i}) at #{judge.dir.to_rel} (#{start.ago} already)...")
|
177
|
+
@loog.info("\nš Running #{judge.name} (##{i}) at #{judge.dir.to_rel} (#{@start.ago} already)...")
|
172
178
|
used += 1
|
173
179
|
elapsed(@loog, level: Logger::INFO) do
|
174
180
|
c = one_judge(opts, fb, judge, global, options, errors)
|
data/lib/judges/options.rb
CHANGED
@@ -86,9 +86,14 @@ class Judges::Options
|
|
86
86
|
# # token ā "supe****oken"
|
87
87
|
def to_s
|
88
88
|
to_h.map do |k, v|
|
89
|
-
v = v.
|
90
|
-
v =
|
91
|
-
|
89
|
+
v = "#{v[0..3]}#{'*' * (v.length - 8)}#{v[-4..]}" if v.is_a?(String) && v.length > 8
|
90
|
+
v =
|
91
|
+
if v.is_a?(String)
|
92
|
+
"\"#{v}\""
|
93
|
+
else
|
94
|
+
"#{v} (#{v.class.name})"
|
95
|
+
end
|
96
|
+
"#{k} ā #{v}"
|
92
97
|
end.sort.join("\n")
|
93
98
|
end
|
94
99
|
|
data/lib/judges.rb
CHANGED
@@ -89,6 +89,18 @@ class TestUpdate < Minitest::Test
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
def test_terminates_on_lifetime
|
93
|
+
Dir.mktmpdir do |d|
|
94
|
+
save_it(File.join(d, 'foo/foo.rb'), 'sleep 999')
|
95
|
+
file = File.join(d, 'base.fb')
|
96
|
+
log = Loog::Buffer.new
|
97
|
+
assert_raises(StandardError) do
|
98
|
+
Judges::Update.new(Loog::Tee.new(log, Loog::NULL)).run({ 'lifetime' => 0.1 }, [d, file])
|
99
|
+
end
|
100
|
+
assert_includes(log.to_s, 'execution expired')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
92
104
|
def test_passes_timeout_and_lifetime_through
|
93
105
|
%w[lifetime timeout].each do |o|
|
94
106
|
Dir.mktmpdir do |d|
|
data/test/test_options.rb
CHANGED
@@ -63,7 +63,7 @@ class TestOptions < Minitest::Test
|
|
63
63
|
def test_converts_to_string
|
64
64
|
opts = Judges::Options.new('foo' => 44, 'bar' => 'long-string-maybe-secret')
|
65
65
|
s = opts.to_s
|
66
|
-
assert_includes(s, 'FOO ā
|
66
|
+
assert_includes(s, 'FOO ā 44 (Integer)', s)
|
67
67
|
assert_includes(s, '"long****************cret"', s)
|
68
68
|
end
|
69
69
|
|