root/trunk/vendor/rails/activerecord/test/threaded_connections_test.rb @ 58

Revision 58, 1.2 KB (checked in by dema, 7 years ago)

Updating to Rails 1.1.2

Line 
1require 'abstract_unit'
2require 'fixtures/topic'
3
4class ThreadedConnectionsTest < Test::Unit::TestCase
5  self.use_transactional_fixtures = false
6
7  fixtures :topics
8
9  def setup
10    @connection = ActiveRecord::Base.remove_connection
11    @connections = []
12    @allow_concurrency = ActiveRecord::Base.allow_concurrency
13  end
14 
15  def teardown
16    # clear the connection cache
17    ActiveRecord::Base.send(:clear_all_cached_connections!)
18    # set allow_concurrency to saved value
19    ActiveRecord::Base.allow_concurrency = @allow_concurrency
20    # reestablish old connection
21    ActiveRecord::Base.establish_connection(@connection)
22  end
23 
24  def gather_connections(use_threaded_connections)
25    ActiveRecord::Base.allow_concurrency = use_threaded_connections
26    ActiveRecord::Base.establish_connection(@connection)
27   
28    5.times do
29      Thread.new do
30        Topic.find :first
31        @connections << ActiveRecord::Base.active_connections.values.first
32      end.join
33    end
34  end
35
36  def test_threaded_connections
37    gather_connections(true)
38    assert_equal @connections.uniq.length, 5
39  end
40
41  def test_unthreaded_connections
42    gather_connections(false)
43    assert_equal @connections.uniq.length, 1
44  end
45end
Note: See TracBrowser for help on using the browser.