Skip to content
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
9 changes: 5 additions & 4 deletions gems/smithy-client/lib/smithy-client/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ module Client
module Features
class << self
def track(*features, &block)
Thread.current[:smithy_ruby_features] ||= []
Thread.current[:smithy_ruby_features].concat(features)
Thread.current[:smithy_ruby_features] ||= Set.new
added = features.map { |f| Thread.current[:smithy_ruby_features].add?(f) }
block.call
ensure
Thread.current[:smithy_ruby_features].pop(features.size)
features.each_with_index { |f, i| Thread.current[:smithy_ruby_features].delete(f) if added[i] }
end

def tracked
Thread.current[:smithy_ruby_features] || []
Thread.current[:smithy_ruby_features] || Set.new
Thread.current[:smithy_ruby_features].to_a
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions gems/smithy-client/spec/smithy-client/features_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ module Client
end
expect(Features.tracked).to be_empty
end

it 'does not track duplicate features' do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think amend this test to push A B at the same time and assert that both get removed together. This properly tests the add/remove logic you made.

Features.track('A', 'B') do
expect(Features.tracked).to eq(%w[A B])
Features.track('A') do
expect(Features.tracked).to eq(%w[A B])
end
expect(Features.tracked).to eq(%w[A B])
end
expect(Features.tracked).to be_empty
end
end
end
end
3 changes: 1 addition & 2 deletions projections/shapes/lib/shapes/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ class Client < Smithy::Client::Base
# @option options [Boolean] :stub_responses
# When `true`, the client will return stubbed responses instead of networking requests.
# By default fake responses are generated and returned. You can specify the response data
# to return or errors to raise by calling {Stubs#stub_responses}.
# @see Stubs
# to return or errors to raise by calling {Smithy::Client::Stubs#stub_responses}.
# @option options [String] :user_agent_suffix
# An optional string that is appended to the User-Agent header.
# The default User-Agent includes the smithy-client version,
Expand Down
3 changes: 1 addition & 2 deletions projections/weather/lib/weather/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ class Client < Smithy::Client::Base
# @option options [Boolean] :stub_responses
# When `true`, the client will return stubbed responses instead of networking requests.
# By default fake responses are generated and returned. You can specify the response data
# to return or errors to raise by calling {Stubs#stub_responses}.
# @see Stubs
# to return or errors to raise by calling {Smithy::Client::Stubs#stub_responses}.
# @option options [String] :user_agent_suffix
# An optional string that is appended to the User-Agent header.
# The default User-Agent includes the smithy-client version,
Expand Down