mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
2c0fa32088
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1399 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
36 lines
1 KiB
Ruby
36 lines
1 KiB
Ruby
require 'abstract_unit'
|
|
require 'fixtures/topic'
|
|
|
|
class ThreadSafetyTest < Test::Unit::TestCase
|
|
self.use_transactional_fixtures = false
|
|
|
|
fixtures :topics
|
|
|
|
def setup
|
|
@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
|