diff options
author | Guilherme Mansur <guilherme.mansur@shopify.com> | 2019-05-21 14:45:29 -0400 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2019-08-05 02:31:53 +0200 |
commit | 6c6d852854ad068acf7d610808ed501b7d13c7f6 (patch) | |
tree | 179dd1e2f399cba1677c095c319986c616ef4f3f /activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb | |
parent | 2bd2d853da78c248b1d50add92ce21f43430abe9 (diff) | |
download | rails-6c6d852854ad068acf7d610808ed501b7d13c7f6.tar.gz rails-6c6d852854ad068acf7d610808ed501b7d13c7f6.tar.bz2 rails-6c6d852854ad068acf7d610808ed501b7d13c7f6.zip |
Use Thread.pass instead of Kernel.sleep to trigger race condition
Diffstat (limited to 'activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb')
-rw-r--r-- | activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb | 21 |
1 files changed, 7 insertions, 14 deletions
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 |