From 6c6d852854ad068acf7d610808ed501b7d13c7f6 Mon Sep 17 00:00:00 2001 From: Guilherme Mansur Date: Tue, 21 May 2019 14:45:29 -0400 Subject: Use Thread.pass instead of Kernel.sleep to trigger race condition --- .../module/attribute_accessor_per_thread_test.rb | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb b/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb index c73ca0be0c..a2b3239884 100644 --- a/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb +++ b/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb @@ -14,7 +14,7 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase class SubMyClass < MyClass end - def setup + setup do @class = MyClass @subclass = SubMyClass @object = @class.new @@ -23,18 +23,11 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase def test_can_initialize_with_default_value Thread.new do @class.thread_mattr_accessor :baz, default: "default_value" - assert_equal "default_value", @class.baz - end.join - end - - def test_can_initialize_with_a_block_as_default_value - Thread.new do - @class.thread_mattr_accessor :baz do - "default_value" - end assert_equal "default_value", @class.baz end.join + + assert_nil @class.baz end def test_should_use_mattr_default @@ -82,23 +75,23 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase threads = [] threads << Thread.new do @class.foo = "things" - sleep 1 + Thread.pass assert_equal "things", @class.foo end threads << Thread.new do @class.foo = "other things" - sleep 1 + Thread.pass assert_equal "other things", @class.foo end threads << Thread.new do @class.foo = "really other things" - sleep 1 + Thread.pass assert_equal "really other things", @class.foo end - threads.each { |t| t.join } + threads.each(&:join) end def test_should_raise_name_error_if_attribute_name_is_invalid -- cgit v1.2.3