File tree Expand file tree Collapse file tree 4 files changed +17
-10
lines changed Expand file tree Collapse file tree 4 files changed +17
-10
lines changed Original file line number Diff line number Diff line change 11language : ruby
22script : ' bundle exec rspec spec'
33rvm :
4- - 1.9.3
5- - 2.0.0
4+ - 2.1.5
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
2323 spec . add_development_dependency "rake"
2424 spec . add_development_dependency "fakeweb"
2525 spec . add_development_dependency "rspec"
26- spec . add_development_dependency "debugger "
26+ spec . add_development_dependency "byebug "
2727
2828 spec . add_runtime_dependency "mixpanel"
2929end
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ def identify(distinct_id)
1919 end
2020
2121 def conditions
22- @conditions ||= assign_conditions!
22+ Thread . current [ :ab_panel_conditions ] ||= assign_conditions!
2323 end
2424
2525 # Set the experiment's conditions.
@@ -28,7 +28,7 @@ def conditions
2828 # the session.
2929 def conditions = ( custom_conditions )
3030 return conditions unless custom_conditions
31- @conditions = assign_conditions! custom_conditions
31+ Thread . current [ :ab_panel_conditions ] = assign_conditions! custom_conditions
3232 end
3333
3434 def experiments
@@ -44,18 +44,18 @@ def weights(experiment)
4444 end
4545
4646 def properties
47- @ env[ :properties ]
47+ env [ :properties ]
4848 end
4949
5050 def env
51- @env ||= {
51+ Thread . current [ :ab_panel_env ] ||= {
5252 'conditions' => conditions
5353 }
5454 end
5555
5656 def reset!
57- @env = nil
58- @conditions = nil
57+ Thread . current [ :ab_panel_env ] = nil
58+ Thread . current [ :ab_panel_conditions ] = nil
5959 end
6060
6161 def set_env ( key , value )
@@ -67,7 +67,7 @@ def funnels
6767 end
6868
6969 def funnels = ( funnels )
70- env [ 'funnels' ] = funnels
70+ Thread . current [ 'ab_panel_env' ] [ 'funnels' ] = funnels
7171 end
7272
7373 def add_funnel ( funnel )
Original file line number Diff line number Diff line change 8888 AbPanel . funnels . to_a . should == funnels . to_a
8989 end
9090 end
91+
92+ describe 'thread-safety' do
93+ it 'should set be safe' do
94+ AbPanel . set_env ( :test , 'a' )
95+ Thread . new { AbPanel . set_env ( :test , 'b' ) } . join
96+ expect ( AbPanel . env [ :test ] ) . to eq 'a'
97+ end
98+ end
9199end
You can’t perform that action at this time.
0 commit comments