Skip to content

Commit

Permalink
Merge pull request #238 from puppetlabs/ensure-post-suite
Browse files Browse the repository at this point in the history
Ensure post-suite and destroy execute
  • Loading branch information
tvpartytonight authored Jan 25, 2024
2 parents 5f0984a + 1d6b1d9 commit 9536cbb
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions tasks/ci.rake
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,14 @@ def beaker_suite(type)
beaker(:provision)

begin
beaker(:exec, 'pre-suite', '--preserve-state', '--pre-suite', pre_suites(type))
beaker(:exec, 'pre-suite', '--preserve-state')
beaker(:exec, ENV.fetch('TESTS', nil))
beaker(:exec, 'post-suite')
begin
beaker(:exec, 'pre-suite', '--preserve-state', '--pre-suite', pre_suites(type))
beaker(:exec, 'pre-suite', '--preserve-state')

beaker(:exec, ENV.fetch('TESTS', nil))
ensure
beaker(:exec, 'post-suite')
end
ensure
preserve_hosts = ENV['OPTIONS'].include?('--preserve-hosts=always') if ENV['OPTIONS']
beaker(:destroy) unless preserve_hosts
Expand All @@ -330,23 +334,26 @@ def beaker_suite_retry(type)
beaker(:provision)

begin
beaker(:exec, 'pre-suite', '--preserve-state', '--pre-suite', pre_suites(type))
beaker(:exec, 'pre-suite', '--preserve-state')

begin
json_results_file = Tempfile.new
beaker(:exec, ENV.fetch('TESTS', nil), '--test-results-file', json_results_file.path)
rescue RuntimeError => e
puts "ERROR: #{e.message}"
tests_to_rerun = JSON.load(File.read(json_results_file.path))
raise e if tests_to_rerun.nil? || tests_to_rerun.empty?

puts '*** Retrying the following:'
puts tests_to_rerun.map { |spec| " #{spec}" }
beaker(:exec, tests_to_rerun.map { |str| "#{str}" }.join(','))
beaker(:exec, 'pre-suite', '--preserve-state', '--pre-suite', pre_suites(type))
beaker(:exec, 'pre-suite', '--preserve-state')

begin
json_results_file = Tempfile.new
beaker(:exec, ENV.fetch('TESTS', nil), '--test-results-file', json_results_file.path)
rescue RuntimeError => e
puts "ERROR: #{e.message}"
tests_to_rerun = JSON.load(File.read(json_results_file.path))
raise e if tests_to_rerun.nil? || tests_to_rerun.empty?

puts '*** Retrying the following:'
puts tests_to_rerun.map { |spec| " #{spec}" }
beaker(:exec, tests_to_rerun.map { |str| "#{str}" }.join(','))
end
ensure
beaker(:exec, 'post-suite')
end
ensure
beaker(:exec, 'post-suite')
preserve_hosts = ENV['OPTIONS'].include?('--preserve-hosts=always') if ENV['OPTIONS']
beaker(:destroy) unless preserve_hosts
end
Expand Down

0 comments on commit 9536cbb

Please sign in to comment.