test/configurations/configuration/test_configure_synchronized.rb in configurations-2.2.0 vs test/configurations/configuration/test_configure_synchronized.rb in configurations-2.2.1

- old
+ new

@@ -1,50 +1,36 @@ require 'test_helper' class TestConfigurationSynchronized < MiniTest::Test - module TestModule + module TestModuleA include Configurations configuration_defaults do |c| - c.a = 'b' + c.a = -1 end end - def test_configuration_synchronized - with_gc_disabled do - ids = [] - threads = 100.times.map do |i| - Thread.new do - sleep rand(1000) / 1000.0 - ids << TestModule.configure do |c| - c.a = i - end.a - end - end - threads.each(&:join) + module TestModuleB + include Configurations - assert_equal 100, ids.uniq.size + configuration_defaults do |c| + c.a = -1 end end - def test_one_instance_mutation - there = TestModule.configuration.a - t = Thread.new do - TestModule.configure do |c| - c.a = 'c' + def test_configuration_synchronized + collector = [] + semaphore = Mutex.new + threads = 100.times.map do |i| + Thread.new do + sleep i%50 / 1000.0 + collector << TestModuleA.configure do |c| + c.a = i + end.a end - - there = TestModule.configuration.a end + threads.each(&:join) - t.join - here = TestModule.configuration.a - - assert_equal here, there + assert_equal 100, collector.uniq.size end - def with_gc_disabled(&_block) - GC.disable - yield - GC.enable - end end