Skip to content

Commit

Permalink
Merge pull request #591 from stripe/ob-fix-590
Browse files Browse the repository at this point in the history
Ensure that each thread has its own client
  • Loading branch information
brandur-stripe authored Oct 12, 2017
2 parents a579368 + a210c5c commit d41a59f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
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

0 comments on commit d41a59f

Please sign in to comment.