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

Ensure that each thread has its own client #591

Merged
merged 1 commit into from
Oct 12, 2017
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
26 changes: 12 additions & 14 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-09-27 21:19:01 +0200 using RuboCop version 0.50.0.
# on 2017-10-12 18:19:29 +0200 using RuboCop version 0.50.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -10,46 +10,44 @@
Metrics/AbcSize:
Max: 49

# Offense count: 22
# Offense count: 24
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 461
Max: 455

# Offense count: 8
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 581
Max: 583

# Offense count: 8
Metrics/CyclomaticComplexity:
Max: 13

# Offense count: 216
# Offense count: 215
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 312
Max: 310

# Offense count: 29
# Offense count: 31
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 47

# Offense count: 2
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 423
Max: 298

# Offense count: 6
# Offense count: 5
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 7

# Offense count: 5
# Offense count: 4
Metrics/PerceivedComplexity:
Max: 11
Exclude:
- 'lib/stripe/stripe_object.rb'
Max: 15

# Offense count: 2
Style/ClassVars:
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def self.active_client
end

def self.default_client
@default_client ||= StripeClient.new(default_conn)
Thread.current[:stripe_client_default_client] ||= StripeClient.new(default_conn)
end

# A default Faraday connection to be used when one isn't configured. This
Expand Down
9 changes: 9 additions & 0 deletions test/stripe/stripe_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class StripeClientTest < Test::Unit::TestCase
should "be a StripeClient" do
assert_kind_of StripeClient, StripeClient.default_client
end

should "be a different client on each thread" do
other_thread_client = nil
thread = Thread.new do
other_thread_client = StripeClient.default_client
end
thread.join
refute_equal StripeClient.default_client, other_thread_client
end
end

context ".default_conn" do
Expand Down