Skip to content

Commit

Permalink
Merge branch 'main' into concurrent-ruby-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcmaw authored Feb 9, 2024
2 parents 4e61bf4 + fed1c55 commit 3821cff
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/mend.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: "mend"

on:
pull_request:
branches:
- "main"
pull_request_target:
types:
- opened
- synchronize
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
Expand Down
8 changes: 6 additions & 2 deletions spec/acceptance/remove_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
it 'saves the setting' do
# Force the command to run if not already
subject.exit_status
expect(File).to exist(ENV.fetch('PDK_ANSWER_FILE', nil))
retry_on_error_matching(60, 5) do
expect(File).to exist(ENV.fetch('PDK_ANSWER_FILE', nil))
end

actual_content = File.open(ENV.fetch('PDK_ANSWER_FILE', nil), 'rb:utf-8', &:read)
expect(actual_content).to eq(new_content)
Expand All @@ -19,7 +21,9 @@
it 'saves the setting' do
# Force the command to run if not already
subject.exit_status
expect(File).to exist(ENV.fetch('PDK_ANSWER_FILE', nil))
retry_on_error_matching(60, 5) do
expect(File).to exist(ENV.fetch('PDK_ANSWER_FILE', nil))
end

actual_content_raw = File.open(ENV.fetch('PDK_ANSWER_FILE', nil), 'rb:utf-8', &:read)
actual_json_content = JSON.parse(actual_content_raw)
Expand Down
3 changes: 1 addition & 2 deletions spec/acceptance/test_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@

describe command('pdk test unit') do
its(:exit_status) { is_expected.not_to eq(0) }
its(:stdout) { is_expected.to match(/An error occurred while loading.*syntax_spec.rb/) }
its(:stdout) { is_expected.to match(/SyntaxError/) }
its(:stdout) { is_expected.to match(/While loading .*syntax_spec.rb a `raise SyntaxError` occurred/) }
end
end

Expand Down
24 changes: 24 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ def default_installed_bin_dir
end
end

# This method allows a block to be passed in and if an exception is raised
# that matches the 'error_matcher' matcher, the block will wait a set number
# of seconds before retrying.
# Params:
# - max_retry_count - Max number of retries
# - retry_wait_interval_secs - Number of seconds to wait before retry
# - error_matcher - Matcher which the exception raised must match to allow retry
# Example Usage:
# retry_on_error_matching(3, 5, /OpenGPG Error/) do
# apply_manifest(pp, :catch_failures => true)
# end
def retry_on_error_matching(max_retry_count = 3, retry_wait_interval_secs = 5, error_matcher = nil)
try = 0
begin
try += 1
yield
rescue StandardError => e
raise unless try < max_retry_count && (error_matcher.nil? || e.message =~ error_matcher)

sleep retry_wait_interval_secs
retry
end
end

module Specinfra
module Backend
class Cmd
Expand Down

0 comments on commit 3821cff

Please sign in to comment.