Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ENV['AWS_MAX_ATTEMPTS'] string value to int #2319

Merged
merged 4 commits into from May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions gems/aws-sdk-core/CHANGELOG.md
@@ -1,5 +1,6 @@
Unreleased Changes
------------------
* Issue - Convert ENV['AWS_MAX_ATTEMPTS'] String value to Integer when set

3.97.0 (2020-05-28)
------------------
Expand Down
2 changes: 1 addition & 1 deletion 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 Down
3 changes: 3 additions & 0 deletions gems/aws-sdk-core/spec/aws/client_spec.rb
Expand Up @@ -3,6 +3,9 @@
module Aws
describe 'Client' do
describe 'response stubbing' do
before(:each) do
stub_const('ENV', {})
end

ResponseStubbingExample = ApiHelper.sample_service

Expand Down
154 changes: 83 additions & 71 deletions gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb
Expand Up @@ -6,97 +6,109 @@ module Plugins
describe RetryErrors do
let(:client) { RetryErrorsSvc::Client.new(stub_responses: true) }

it 'can configure retry_mode with shared config' do
allow_any_instance_of(Aws::SharedConfig)
.to receive(:retry_mode).and_return('standard')
expect(client.config.retry_mode).to eq('standard')
end
context 'ENV is stubbed' do
before(:each) do
stub_const('ENV', {})
end

it 'can configure retry_mode using ENV with precedence over config' do
allow_any_instance_of(Aws::SharedConfig)
.to receive(:retry_mode).and_return('standard')
ENV['AWS_RETRY_MODE'] = 'adaptive'
expect(client.config.retry_mode).to eq('adaptive')
end
it 'can configure retry_mode with shared config' do
allow_any_instance_of(Aws::SharedConfig)
.to receive(:retry_mode).and_return('standard')
expect(client.config.retry_mode).to eq('standard')
end

it 'raises when retry_mode is not legacy, standard, or adaptive' do
ENV['AWS_RETRY_MODE'] = 'peccy'
expect { client }.to raise_error(ArgumentError)
end
it 'can configure retry_mode using ENV with precedence over config' do
allow_any_instance_of(Aws::SharedConfig)
.to receive(:retry_mode).and_return('standard')
ENV['AWS_RETRY_MODE'] = 'adaptive'
expect(client.config.retry_mode).to eq('adaptive')
end

it 'uses the handler when retry_mode is standard' do
client = RetryErrorsSvc::Client.new(retry_mode: 'standard',
region: 'us-west-2')
expect(client.handlers.entries.map(&:handler_class)).
to include(RetryErrors::Handler)
end
it 'raises when retry_mode is not legacy, standard, or adaptive' do
ENV['AWS_RETRY_MODE'] = 'peccy'
expect { client }.to raise_error(ArgumentError)
end

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

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

it 'can configure max_attempts with shared config' do
allow_any_instance_of(Aws::SharedConfig)
.to receive(:max_attempts).and_return(5)
expect(client.config.max_attempts).to eq(5)
end
it 'defaults config.max_attempts to 3' do
expect(client.config.max_attempts).to eq(3)
end

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
expect(client.config.max_attempts).to eq(1)
end
it 'can configure max_attempts with shared config' do
allow_any_instance_of(Aws::SharedConfig)
.to receive(:max_attempts).and_return(5)
expect(client.config.max_attempts).to eq(5)
end

it 'raises when max_attempts is not an integer' do
ENV['AWS_MAX_ATTEMPTS'] = 'string'
expect { client }.to raise_error(ArgumentError)
end
it 'defaults config.adaptive_retry_wait_to_fill to true' do
expect(client.config.adaptive_retry_wait_to_fill).to eq(true)
end

it 'raises when max_attempts is not >= 0' do
ENV['AWS_MAX_ATTEMPTS'] = -1
expect { client }.to raise_error(ArgumentError)
end
it 'can configure adaptive_retry_wait_to_fill using ENV with precedence over config' do
ENV['AWS_ADAPTIVE_RETRY_WAIT_TO_FILL'] = 'false'
expect(client.config.adaptive_retry_wait_to_fill).to eq(false)
end

it 'defaults config.adaptive_retry_wait_to_fill to true' do
expect(client.config.adaptive_retry_wait_to_fill).to eq(true)
end
it 'can configure adaptive_retry_wait_to_fill with shared config' do
allow_any_instance_of(Aws::SharedConfig)
.to receive(:adaptive_retry_wait_to_fill).and_return('false')
expect(client.config.adaptive_retry_wait_to_fill).to eq(false)
end

it 'can configure adaptive_retry_wait_to_fill using ENV with precedence over config' do
ENV['AWS_ADAPTIVE_RETRY_WAIT_TO_FILL'] = 'false'
expect(client.config.adaptive_retry_wait_to_fill).to eq(false)
end
it 'defaults config.correct_clock_skew to true' do
expect(client.config.correct_clock_skew).to eq(true)
end

it 'can configure adaptive_retry_wait_to_fill with shared config' do
allow_any_instance_of(Aws::SharedConfig)
.to receive(:adaptive_retry_wait_to_fill).and_return('false')
expect(client.config.adaptive_retry_wait_to_fill).to eq(false)
end
it 'can configure correct_clock_skew using ENV with precedence over config' do
ENV['AWS_CORRECT_CLOCK_SKEW'] = 'true'
expect(client.config.correct_clock_skew).to eq(true)
end

it 'defaults config.correct_clock_skew to true' do
expect(client.config.correct_clock_skew).to eq(true)
it 'can configure correct_clock_skew with shared config' do
allow_any_instance_of(Aws::SharedConfig)
.to receive(:correct_clock_skew).and_return('true')
expect(client.config.correct_clock_skew).to eq(true)
end
end

it 'can configure correct_clock_skew using ENV with precedence over config' do
ENV['AWS_CORRECT_CLOCK_SKEW'] = 'true'
expect(client.config.correct_clock_skew).to eq(true)
end
context 'ENV is not stubbed' do
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'
mullermp marked this conversation as resolved.
Show resolved Hide resolved
expect(client.config.max_attempts).to eq(1)
end

it 'raises when max_attempts is not an integer' do
ENV['AWS_MAX_ATTEMPTS'] = 'string'
expect { client }.to raise_error(ArgumentError)
end

it 'can configure correct_clock_skew with shared config' do
allow_any_instance_of(Aws::SharedConfig)
.to receive(:correct_clock_skew).and_return('true')
expect(client.config.correct_clock_skew).to eq(true)
it 'raises when max_attempts is not >= 0' do
ENV['AWS_MAX_ATTEMPTS'] = '-1'
expect { client }.to raise_error(ArgumentError)
end
end
end

describe RetryErrors::Handler do
before(:each) do
stub_const('ENV', {})
end

let(:credentials) { Credentials.new('akid', 'secret') }

let(:cache) { EndpointCache.new }
Expand Down
3 changes: 3 additions & 0 deletions gems/aws-sdk-core/spec/aws/plugins/signature_v4_spec.rb
Expand Up @@ -3,6 +3,9 @@
module Aws
module Plugins
describe SignatureV4 do
before(:each) do
stub_const('ENV', {})
end

Sigv4Client = ApiHelper.sample_service(metadata: {
'signatureVersion' => 'v4',
Expand Down
4 changes: 4 additions & 0 deletions gems/aws-sdk-core/spec/aws/sts/client_spec.rb
Expand Up @@ -3,6 +3,10 @@
module Aws
module STS
describe Client do
before(:each) do
stub_const('ENV', {})
end

it 'constructs the proper endpoint in gov-cloud' do
client = Client.new(
region: 'us-gov-west-1',
Expand Down
1 change: 1 addition & 0 deletions gems/aws-sdk-core/spec/aws/sts/presigner_spec.rb
Expand Up @@ -7,6 +7,7 @@ module STS
allow(Time).to receive(:now).and_return(now)
allow(now).to receive(:utc).and_return(utc)
allow(utc).to receive(:strftime).and_return(datetime)
stub_const('ENV', {})
end

let(:now) { double('now') }
Expand Down
3 changes: 3 additions & 0 deletions gems/aws-sdk-core/spec/aws/sts/sts_regional_endpoints_spec.rb
Expand Up @@ -3,6 +3,9 @@
module Aws
module STS
describe Client do
before(:each) do
stub_const('ENV', {})
end

describe ':sts_regional_endpoints' do

Expand Down
3 changes: 3 additions & 0 deletions gems/aws-sdk-core/spec/aws/stubbing/empty_stub_spec.rb
Expand Up @@ -4,6 +4,9 @@
module Aws
module Stubbing
describe EmptyStub do
before(:each) do
stub_const('ENV', {})
end

it 'supports complex recursive structures' do
now = Time.now
Expand Down
3 changes: 3 additions & 0 deletions gems/aws-sdk-core/spec/aws/waiters_spec.rb
Expand Up @@ -3,6 +3,9 @@
module Aws
module Waiters
describe 'Waiters' do
before(:each) do
stub_const('ENV', {})
end

dir = File.expand_path('../../fixtures/waiters', __FILE__)
WaiterTest = ApiHelper.sample_service(
Expand Down
3 changes: 3 additions & 0 deletions gems/aws-sdk-core/spec/aws/xml/error_handler_spec.rb
Expand Up @@ -3,6 +3,9 @@
module Aws
module Xml
describe ErrorHandler do
before(:each) do
stub_const('ENV', {})
end

let(:cloudfront) {
ApiHelper.sample_service(
Expand Down
5 changes: 1 addition & 4 deletions gems/aws-sdk-core/spec/shared_spec_helper.rb
Expand Up @@ -15,9 +15,6 @@
#
RSpec.configure do |config|
config.before(:each) do

stub_const('ENV', {})
mullermp marked this conversation as resolved.
Show resolved Hide resolved

# disable loading credentials from shared file
allow(Dir).to receive(:home).and_raise(ArgumentError)

Expand All @@ -43,4 +40,4 @@

Thread.report_on_exception = current_value if current_value
end
end
end