Skip to content

Commit 67b1747

Browse files
committed
Thread safety specs
1 parent 38fa924 commit 67b1747

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

spec/config_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,28 @@
108108
end
109109
end # describe 'max_group_results'
110110

111+
describe 'thread safety' do
112+
it 'uses thread-local global config values' do
113+
thread = Thread.new do
114+
RegexpExamples::Config.max_group_results = 1
115+
expect(/\d/.examples).to eq %w(0)
116+
end
117+
sleep 0.1 # Give the above thread time to run
118+
expect(/\d/.examples).to eq %w(0 1 2 3 4)
119+
thread.join
120+
end
121+
122+
it 'uses thread-local block config values' do
123+
thread = Thread.new do
124+
RegexpExamples::Config.with_configuration(max_group_results: 1) do
125+
expect(/\d/.examples).to eq %w(0)
126+
sleep 0.2 # Give the below thread time to run while this block is open
127+
end
128+
end
129+
sleep 0.1 # Give the above thread time to run
130+
expect(/\d/.examples).to eq %w(0 1 2 3 4)
131+
thread.join
132+
end
133+
end # describe 'thread safety'
134+
111135
end

0 commit comments

Comments
 (0)