Skip to content

Commit e52a7b8

Browse files
committed
Fail incomplete worker-history retries
1 parent 7149f0b commit e52a7b8

5 files changed

Lines changed: 69 additions & 13 deletions

File tree

‎ruby/lib/ci/queue/redis.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module CI
1717
module Queue
1818
module Redis
1919
Error = Class.new(StandardError)
20+
IncompleteRetry = Class.new(Error)
2021
LostMaster = Class.new(Error)
2122
WorkerHistoryError = Class.new(Error)
2223

‎ruby/lib/ci/queue/redis/retry.rb‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@ module CI
33
module Queue
44
module Redis
55
class Retry < Static
6-
def initialize(tests, config, redis:)
6+
def initialize(tests, config, redis:, require_exhaustion: false)
77
@redis = redis
8+
@require_exhaustion = require_exhaustion
89
super(tests, config)
910
end
1011

1112
def build
1213
@build ||= CI::Queue::Redis::BuildRecord.new(self, redis, config)
1314
end
1415

16+
def poll
17+
super
18+
return unless require_exhaustion
19+
return if exhausted?
20+
21+
raise IncompleteRetry, 'Worker history replay stopped before completion'
22+
end
23+
1524
private
1625

17-
attr_reader :redis
26+
attr_reader :redis, :require_exhaustion
1827
end
1928
end
2029
end

‎ruby/lib/ci/queue/redis/worker.rb‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ def retry_queue(selection: :failed_tests)
156156
raise ArgumentError, "Unknown retry selection: #{selection.inspect}"
157157
end
158158

159-
Retry.new(test_ids, config, redis: redis)
159+
Retry.new(
160+
test_ids,
161+
config,
162+
redis: redis,
163+
require_exhaustion: selection == :worker_history
164+
)
160165
end
161166

162167
def supervisor

‎ruby/test/ci/queue/redis_test.rb‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ def test_worker_history_retry_requires_reservations
7979
assert_equal 'Reservation history is missing for worker 1', error.message
8080
end
8181

82+
def test_worker_history_retry_requires_complete_replay
83+
poll(@queue)
84+
retry_queue = populate(@queue.retry_queue(selection: :worker_history))
85+
86+
error = assert_raises(CI::Queue::Redis::IncompleteRetry) do
87+
retry_queue.poll do
88+
retry_queue.shutdown!
89+
end
90+
end
91+
92+
assert_equal 'Worker history replay stopped before completion', error.message
93+
refute_predicate retry_queue, :exhausted?
94+
end
95+
8296
def test_retry_queue_rejects_unknown_selection
8397
error = assert_raises(ArgumentError) do
8498
@queue.retry_queue(selection: :everything)

‎ruby/test/integration/minitest_redis_test.rb‎

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,23 @@ def test_worker_history_retry_fails_without_worker_reservations
241241
assert_includes out, 'Reservation history is missing for worker 2'
242242
end
243243

244+
def test_worker_history_retry_fails_when_replay_stops_early
245+
run_worker_history_worker(
246+
retry_count: 0,
247+
build_id: 'incomplete-history',
248+
test_file: 'test/failing_test.rb'
249+
)
250+
out, err = run_worker_history_worker(
251+
retry_count: 1,
252+
build_id: 'incomplete-history',
253+
test_file: 'test/failing_test.rb',
254+
extra_args: ['--max-consecutive-failures', '1']
255+
)
256+
257+
refute_predicate $?, :success?
258+
assert_includes out + err, 'Worker history replay stopped before completion'
259+
end
260+
244261
def test_retry_fails_when_test_run_is_expired
245262
out, err = capture_subprocess_io do
246263
system(
@@ -809,19 +826,29 @@ def test_utf8_tests_and_marshal
809826

810827
private
811828

812-
def run_worker_history_worker(retry_count:, build_id: 'worker-history', worker_id: '1')
829+
def run_worker_history_worker(
830+
retry_count:,
831+
build_id: 'worker-history',
832+
worker_id: '1',
833+
test_file: 'test/passing_test.rb',
834+
extra_args: []
835+
)
836+
args = [
837+
@exe, 'run',
838+
'--queue', @redis_url,
839+
'--seed', 'foobar',
840+
'--build', build_id,
841+
'--worker', worker_id,
842+
'--timeout', '1',
843+
'--retry-selection', 'worker-history'
844+
]
845+
args.concat(extra_args)
846+
args.push('-Itest', test_file)
847+
813848
capture_subprocess_io do
814849
system(
815850
{ 'BUILDKITE_RETRY_COUNT' => retry_count.to_s },
816-
@exe, 'run',
817-
'--queue', @redis_url,
818-
'--seed', 'foobar',
819-
'--build', build_id,
820-
'--worker', worker_id,
821-
'--timeout', '1',
822-
'--retry-selection', 'worker-history',
823-
'-Itest',
824-
'test/passing_test.rb',
851+
*args,
825852
chdir: 'test/fixtures/'
826853
)
827854
end

0 commit comments

Comments
 (0)