Skip to content

Commit

Permalink
Convert ENV['AWS_MAX_ATTEMPTS'] string value to int (#2319)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseadams committed May 29, 2020
1 parent f310d88 commit 004ac23
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions gems/aws-sdk-core/CHANGELOG.md
@@ -1,6 +1,7 @@
Unreleased Changes
------------------

* Issue - Convert ENV['AWS_MAX_ATTEMPTS'] String value to Integer when set. (#2319)
* Issue - Handle unknown and unmodeled events from event streams by ignoring them and providing a new callback rather than raising an error.

3.97.0 (2020-05-28)
Expand Down
6 changes: 1 addition & 5 deletions gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb
Expand Up @@ -174,7 +174,7 @@ def self.resolve_retry_mode(cfg)
end

def self.resolve_max_attempts(cfg)
value = ENV['AWS_MAX_ATTEMPTS'] ||
value = (ENV['AWS_MAX_ATTEMPTS'] && ENV['AWS_MAX_ATTEMPTS'].to_i) ||
Aws.shared_config.max_attempts(profile: cfg.profile) ||
3
# Raise if provided value is not a positive integer
Expand All @@ -190,31 +190,27 @@ def self.resolve_adaptive_retry_wait_to_fill(cfg)
value = ENV['AWS_ADAPTIVE_RETRY_WAIT_TO_FILL'] ||
Aws.shared_config.adaptive_retry_wait_to_fill(profile: cfg.profile) ||
'true'

# Raise if provided value is not true or false
if value != 'true' && value != 'false'
raise ArgumentError,
'Must provide either `true` or `false` for '\
'adaptive_retry_wait_to_fill profile option or for '\
'ENV[\'AWS_ADAPTIVE_RETRY_WAIT_TO_FILL\']'
end

value == 'true'
end

def self.resolve_correct_clock_skew(cfg)
value = ENV['AWS_CORRECT_CLOCK_SKEW'] ||
Aws.shared_config.correct_clock_skew(profile: cfg.profile) ||
'true'

# Raise if provided value is not true or false
if value != 'true' && value != 'false'
raise ArgumentError,
'Must provide either `true` or `false` for '\
'correct_clock_skew profile option or for '\
'ENV[\'AWS_CORRECT_CLOCK_SKEW\']'
end

value == 'true'
end

Expand Down
14 changes: 8 additions & 6 deletions gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb
Expand Up @@ -25,15 +25,17 @@ module Plugins
end

it 'uses the handler when retry_mode is standard' do
client = RetryErrorsSvc::Client.new(retry_mode: 'standard',
region: 'us-west-2')
client = RetryErrorsSvc::Client.new(
retry_mode: 'standard', region: 'us-west-2'
)
expect(client.handlers.entries.map(&:handler_class)).
to include(RetryErrors::Handler)
end

it 'uses the handler when retry_mode is adaptive' do
client = RetryErrorsSvc::Client.new(retry_mode: 'adaptive',
region: 'us-west-2')
client = RetryErrorsSvc::Client.new(
retry_mode: 'adaptive', region: 'us-west-2'
)
expect(client.handlers.entries.map(&:handler_class))
.to include(RetryErrors::Handler)
end
Expand All @@ -51,7 +53,7 @@ module Plugins
it 'can configure max_attempts using ENV with precedence over config' do
allow_any_instance_of(Aws::SharedConfig)
.to receive(:max_attempts).and_return(3)
ENV['AWS_MAX_ATTEMPTS'] = 1
ENV['AWS_MAX_ATTEMPTS'] = '1'
expect(client.config.max_attempts).to eq(1)
end

Expand All @@ -61,7 +63,7 @@ module Plugins
end

it 'raises when max_attempts is not >= 0' do
ENV['AWS_MAX_ATTEMPTS'] = -1
ENV['AWS_MAX_ATTEMPTS'] = '-1'
expect { client }.to raise_error(ArgumentError)
end

Expand Down
Expand Up @@ -49,7 +49,7 @@ def endpoint

it 're-uses session for slow request that are taking more time than the configured idle timeout' do
session = double('http-session').as_null_object
session.stub(:request) { sleep 2 }
allow(session).to receive(:request) { sleep 2 }
pool = ConnectionPool.for(http_idle_timeout: 1)
expect(pool).to receive(:start_session).
exactly(1).times.
Expand Down
7 changes: 4 additions & 3 deletions gems/aws-sdk-core/spec/shared_spec_helper.rb
Expand Up @@ -15,8 +15,9 @@
#
RSpec.configure do |config|
config.before(:each) do

stub_const('ENV', {})
# Clear the current ENV to avoid loading credentials.
# This was previously mocked with stub_const but was provided a hash.
ENV.clear

# disable loading credentials from shared file
allow(Dir).to receive(:home).and_raise(ArgumentError)
Expand All @@ -43,4 +44,4 @@

Thread.report_on_exception = current_value if current_value
end
end
end

0 comments on commit 004ac23

Please sign in to comment.