From 67b1747ce0b22dbff586426c161c27a2d094523d Mon Sep 17 00:00:00 2001 From: Tom Lord Date: Sun, 15 Oct 2017 21:50:32 +0100 Subject: [PATCH] Thread safety specs --- spec/config_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 5dd6f28..51f3380 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -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