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

Make stubs thread safe by adding a mutex per stubbed request #2679

Merged
merged 4 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Issue - Make stubs thread safe by creating new responses for each operation call (#2675).

3.129.0 (2022-03-08)
------------------

Expand Down
6 changes: 5 additions & 1 deletion gems/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,17 @@ def apply_stubs(operation_name, stubs)
end

def convert_stub(operation_name, stub)
case stub
stub = case stub
when Proc then stub
when Exception, Class then { error: stub }
when String then service_error_stub(stub)
when Hash then http_response_stub(operation_name, stub)
else { data: stub }
end
if Hash === stub
stub[:mutex] = Mutex.new
end
mullermp marked this conversation as resolved.
Show resolved Hide resolved
stub
end

def service_error_stub(error_code)
Expand Down
6 changes: 5 additions & 1 deletion gems/aws-sdk-core/lib/aws-sdk-core/plugins/stub_responses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def call(context)
stub = context.client.next_stub(context)
resp = Seahorse::Client::Response.new(context: context)
async_mode = context.client.is_a? Seahorse::Client::AsyncBase
apply_stub(stub, resp, async_mode)
if Hash === stub && stub[:mutex]
stub[:mutex].synchronize { apply_stub(stub, resp, async_mode) }
else
apply_stub(stub, resp, async_mode)
end

async_mode ? Seahorse::Client::AsyncResponse.new(
context: context, stream: context[:input_event_stream_handler].event_emitter.stream, sync_queue: Queue.new) : resp
Expand Down