This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 11### Development
22[ Full Changelog] ( http://github.com/rspec/rspec-support/compare/v3.12.0...3-12-maintenance )
33
4+ Bug Fixes:
5+
6+ * Fix ` RSpec::Support.thread_local_data ` to be Thread local but not Fiber local.
7+ (Jon Rowe, #581 )
8+
49### 3.12.0 / 2022-10-26
510[ Full Changelog] ( http://github.com/rspec/rspec-support/compare/v3.11.1...v3.12.0 )
611Enhancements:
Original file line number Diff line number Diff line change @@ -89,8 +89,14 @@ def self.class_of(object)
8989 end
9090
9191 # A single thread local variable so we don't excessively pollute that namespace.
92- def self . thread_local_data
93- Thread . current [ :__rspec ] ||= { }
92+ if RUBY_VERSION . to_f >= 2
93+ def self . thread_local_data
94+ Thread . current . thread_variable_get ( :__rspec ) || Thread . current . thread_variable_set ( :__rspec , { } )
95+ end
96+ else
97+ def self . thread_local_data
98+ Thread . current [ :__rspec ] ||= { }
99+ end
94100 end
95101
96102 # @api private
Original file line number Diff line number Diff line change @@ -186,6 +186,26 @@ def object.some_method
186186 end
187187 end
188188
189+ describe ".thread_local_data" do
190+ it "contains data local to the current thread" do
191+ RSpec ::Support . thread_local_data [ :__for_test ] = :oh_hai
192+
193+ Thread . new do
194+ expect ( RSpec ::Support . thread_local_data ) . to eq ( { } )
195+ end . join
196+ end
197+
198+ if defined? ( Fiber ) && RUBY_VERSION . to_f >= 2.0
199+ it "shares data across fibres" do
200+ RSpec ::Support . thread_local_data [ :__for_test ] = :oh_hai
201+
202+ Fiber . new do
203+ expect ( RSpec ::Support . thread_local_data [ :__for_test ] ) . to eq ( :oh_hai )
204+ end . resume
205+ end
206+ end
207+ end
208+
189209 describe "failure notification" do
190210 before { @failure_notifier = RSpec ::Support . failure_notifier }
191211 after { RSpec ::Support . failure_notifier = @failure_notifier }
You can’t perform that action at this time.
0 commit comments