Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
Resolved a thread-safety test issue with JRuby.
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorrowe committed Oct 10, 2014
1 parent 725b07f commit 3e897b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 18 additions & 11 deletions aws-sdk-core/lib/aws-sdk-core/client_stubs.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'thread'

module Aws

# This module provides the ability to specify the data and/or errors to
Expand All @@ -8,6 +10,7 @@ module ClientStubs

def initialize(*args)
@stubs = {}
@stub_mutex = Mutex.new
super
end

Expand Down Expand Up @@ -83,11 +86,13 @@ def stub_responses(operation_name, *stubs)

# @api private
def next_stub(operation_name)
stubs = @stubs[operation_name.to_sym] || []
case stubs.length
when 0 then new_stub(operation_name)
when 1 then stubs.first
else stubs.shift
@stub_mutex.synchronize do
stubs = @stubs[operation_name.to_sym] || []
case stubs.length
when 0 then new_stub(operation_name)
when 1 then stubs.first
else stubs.shift
end
end
end

Expand All @@ -101,12 +106,14 @@ def new_stub(operation_name, data = nil)
end

def apply_stubs(operation_name, stubs)
@stubs[operation_name.to_sym] = stubs.map do |stub|
case stub
when Exception then stub
when String then service_error_class(stub)
when Hash then new_stub(operation_name, stub)
else stub
@stub_mutex.synchronize do
@stubs[operation_name.to_sym] = stubs.map do |stub|
case stub
when Exception then stub
when String then service_error_class(stub)
when Hash then new_stub(operation_name, stub)
else stub
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions aws-sdk-resources/spec/s3/object/upload_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ module S3

it 'automatically deletes failed multipart upload on error' do

allow_any_instance_of(FilePart).to receive(:read).and_return(nil)

client.stub_responses(:upload_part, [
{ etag: 'etag-1' },
{ etag: 'etag-2' },
Expand Down

0 comments on commit 3e897b1

Please sign in to comment.