From 3e897b123df6a44bd1900fd1dd9a0773b2cf44f9 Mon Sep 17 00:00:00 2001 From: Trevor Rowe Date: Fri, 10 Oct 2014 15:36:21 -0700 Subject: [PATCH] Resolved a thread-safety test issue with JRuby. --- aws-sdk-core/lib/aws-sdk-core/client_stubs.rb | 29 ++++++++++++------- .../spec/s3/object/upload_file_spec.rb | 2 ++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb b/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb index 59cccfcb..61897596 100644 --- a/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb +++ b/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb @@ -1,3 +1,5 @@ +require 'thread' + module Aws # This module provides the ability to specify the data and/or errors to @@ -8,6 +10,7 @@ module ClientStubs def initialize(*args) @stubs = {} + @stub_mutex = Mutex.new super end @@ -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 @@ -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 diff --git a/aws-sdk-resources/spec/s3/object/upload_file_spec.rb b/aws-sdk-resources/spec/s3/object/upload_file_spec.rb index 4c5b1503..3f2fe607 100644 --- a/aws-sdk-resources/spec/s3/object/upload_file_spec.rb +++ b/aws-sdk-resources/spec/s3/object/upload_file_spec.rb @@ -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' },