aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/serialized_attribute_test.rb
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-05-26 08:06:16 +0930
committerGitHub <noreply@github.com>2017-05-26 08:06:16 +0930
commitb2556fd8a4bc42beabf25dd199fd454963ccd754 (patch)
treea0a17622bb421f4d37f45952fb935e0149803b2f /activerecord/test/cases/serialized_attribute_test.rb
parentaee5ef3d67664e964f5adc2ead6e1fe64e5b13dc (diff)
parent6a5a814eaa0d4f98d6151df5bd96cc8ec1ae5675 (diff)
downloadrails-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/cases/serialized_attribute_test.rb')
-rw-r--r--activerecord/test/cases/serialized_attribute_test.rb28
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