Skip to content

Commit

Permalink
Thread safety specs
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-lord committed Oct 15, 2017
1 parent 38fa924 commit 67b1747
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,28 @@
end
end # describe 'max_group_results'

describe 'thread safety' do
it 'uses thread-local global config values' do
thread = Thread.new do
RegexpExamples::Config.max_group_results = 1
expect(/\d/.examples).to eq %w(0)
end
sleep 0.1 # Give the above thread time to run
expect(/\d/.examples).to eq %w(0 1 2 3 4)
thread.join
end

it 'uses thread-local block config values' do
thread = Thread.new do
RegexpExamples::Config.with_configuration(max_group_results: 1) do
expect(/\d/.examples).to eq %w(0)
sleep 0.2 # Give the below thread time to run while this block is open
end
end
sleep 0.1 # Give the above thread time to run
expect(/\d/.examples).to eq %w(0 1 2 3 4)
thread.join
end
end # describe 'thread safety'

end

0 comments on commit 67b1747

Please sign in to comment.