@@ -220,6 +220,50 @@ def test_retry_success
220220 assert_equal 'All tests were ran already' , output
221221 end
222222
223+ def test_worker_history_retry_writes_recovery_manifest
224+ Dir . mktmpdir do |directory |
225+ manifest_path = File . join ( directory , 'recovery.json' )
226+ run_worker_history_worker ( manifest_path , retry_count : 0 )
227+
228+ first_manifest = JSON . parse ( File . read ( manifest_path ) )
229+ assert_equal 0 , first_manifest [ 'retry_count' ]
230+ assert_equal 0 , first_manifest [ 'history_items' ]
231+ assert_equal 0 , first_manifest [ 'replayed_tests' ]
232+ refute first_manifest [ 'resumed_shared_queue' ]
233+ assert first_manifest [ 'replay_completed' ]
234+
235+ out , = run_worker_history_worker ( manifest_path , retry_count : 1 )
236+
237+ assert_includes out , 'Replaying 100 tests from 100 worker reservations.'
238+ retry_manifest = JSON . parse ( File . read ( manifest_path ) )
239+ assert_equal 1 , retry_manifest [ 'schema_version' ]
240+ assert_equal '1' , retry_manifest [ 'worker_id' ]
241+ assert_equal 1 , retry_manifest [ 'retry_count' ]
242+ assert_equal 100 , retry_manifest [ 'history_items' ]
243+ assert_equal 100 , retry_manifest [ 'replayed_tests' ]
244+ assert retry_manifest [ 'resumed_shared_queue' ]
245+ assert retry_manifest [ 'replay_completed' ]
246+ end
247+ end
248+
249+ def test_worker_history_retry_fails_without_worker_reservations
250+ run_worker_history_worker ( nil , retry_count : 0 , build_id : 'missing-history' , worker_id : '1' )
251+
252+ Dir . mktmpdir do |directory |
253+ manifest_path = File . join ( directory , 'recovery.json' )
254+ out , = run_worker_history_worker (
255+ manifest_path ,
256+ retry_count : 1 ,
257+ build_id : 'missing-history' ,
258+ worker_id : '2'
259+ )
260+
261+ refute_predicate $?, :success?
262+ assert_includes out , 'Reservation history is missing for worker 2'
263+ refute_path_exists manifest_path
264+ end
265+ end
266+
223267 def test_retry_fails_when_test_run_is_expired
224268 out , err = capture_subprocess_io do
225269 system (
@@ -788,6 +832,28 @@ def test_utf8_tests_and_marshal
788832
789833 private
790834
835+ def run_worker_history_worker ( manifest_path , retry_count :, build_id : 'worker-history' , worker_id : '1' )
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-mode' , 'worker-history'
844+ ]
845+ args . push ( '--recovery-manifest' , manifest_path ) if manifest_path
846+ args . push ( '-Itest' , 'test/passing_test.rb' )
847+
848+ capture_subprocess_io do
849+ system (
850+ { 'BUILDKITE_RETRY_COUNT' => retry_count . to_s } ,
851+ *args ,
852+ chdir : 'test/fixtures/'
853+ )
854+ end
855+ end
856+
791857 def normalize_xml ( output )
792858 freeze_xml_timing ( rewrite_paths ( output ) )
793859 end
0 commit comments