diff options
author | Matthew Draper <matthew@trebex.net> | 2017-05-26 08:06:16 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-26 08:06:16 +0930 |
commit | b2556fd8a4bc42beabf25dd199fd454963ccd754 (patch) | |
tree | a0a17622bb421f4d37f45952fb935e0149803b2f /activerecord/test | |
parent | aee5ef3d67664e964f5adc2ead6e1fe64e5b13dc (diff) | |
parent | 6a5a814eaa0d4f98d6151df5bd96cc8ec1ae5675 (diff) | |
download | rails-b2556fd8a4bc42beabf25dd199fd454963ccd754.tar.gz rails-b2556fd8a4bc42beabf25dd199fd454963ccd754.tar.bz2 rails-b2556fd8a4bc42beabf25dd199fd454963ccd754.zip |
Merge pull request #29216 from matthewd/threadsafe-load-schema
Add a Monitor to ModelSchema#load_schema
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/serialized_attribute_test.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb index 673392b4c4..e1bdaab5cf 100644 --- a/activerecord/test/cases/serialized_attribute_test.rb +++ b/activerecord/test/cases/serialized_attribute_test.rb @@ -349,4 +349,32 @@ class SerializedAttributeTest < ActiveRecord::TestCase topic.foo refute topic.changed? end + + def test_serialized_attribute_works_under_concurrent_initial_access + model = Topic.dup + + topic = model.last + topic.update group: "1" + + model.serialize :group, JSON + model.reset_column_information + + # This isn't strictly necessary for the test, but a little bit of + # knowledge of internals allows us to make failures far more likely. + model.define_singleton_method(:define_attribute) do |*args| + Thread.pass + super(*args) + end + + threads = 4.times.map do + Thread.new do + topic.reload.group + end + end + + # All the threads should retrieve the value knowing it is JSON, and + # thus decode it. If this fails, some threads will instead see the + # raw string ("1"), or raise an exception. + assert_equal [1] * threads.size, threads.map(&:value) + end end |