diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-11-24 01:04:44 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-11-24 01:04:44 +0000 |
commit | db045dbbf60b53dbe013ef25554fd013baf88134 (patch) | |
tree | 257830e3c76458c8ff3d1329de83f32b23926028 /activerecord/test/thread_safety_test.rb | |
download | rails-db045dbbf60b53dbe013ef25554fd013baf88134.tar.gz rails-db045dbbf60b53dbe013ef25554fd013baf88134.tar.bz2 rails-db045dbbf60b53dbe013ef25554fd013baf88134.zip |
Initial
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/thread_safety_test.rb')
-rw-r--r-- | activerecord/test/thread_safety_test.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/activerecord/test/thread_safety_test.rb b/activerecord/test/thread_safety_test.rb new file mode 100644 index 0000000000..635240c6af --- /dev/null +++ b/activerecord/test/thread_safety_test.rb @@ -0,0 +1,33 @@ +require 'abstract_unit' +require 'fixtures/topic' + +class ThreadSafetyTest < Test::Unit::TestCase + def setup + @topics = create_fixtures "topics" + @threads = [] + end + + def test_threading_on_transactions + # SQLite breaks down under thread banging + # Jamis Buck (author of SQLite-ruby): "I know that sqlite itself is not designed for concurrent access" + if ActiveRecord::ConnectionAdapters.const_defined? :SQLiteAdapter + return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLiteAdapter) + end + + 5.times do |thread_number| + @threads << Thread.new(thread_number) do |thread_number| + first, second = Topic.find(1, 2) + Topic.transaction(first, second) do + Topic.logger.info "started #{thread_number}" + first.approved = 1 + second.approved = 0 + first.save + second.save + Topic.logger.info "ended #{thread_number}" + end + end + end + + @threads.each { |t| t.join } + end +end |