Skip to content

Commit fa9f549

Browse files
committed
Connection pool warmup test
1 parent dcdba98 commit fa9f549

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

test/connection_pool_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require "#{File.dirname(__FILE__)}/helper"
2+
3+
Mysqlplus::Test.prepare!
4+
5+
class ConnectionPoolTest < ActiveSupport::TestCase
6+
7+
test "should not establish connections in a lazy manner when warmed up" do
8+
ActiveRecord::Base.connection_pool.expects(:checkout_new_connection).never
9+
5.times do
10+
ActiveRecord::Base.connection_pool.checkout
11+
end
12+
end
13+
14+
end

test/deferrable/result_test.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require "#{File.dirname(__FILE__)}/../helper"
2+
3+
Mysqlplus::Test.prepare!
4+
5+
class ResultTest < ActiveSupport::TestCase
6+
7+
def teardown
8+
ActiveRecord::Base.clear_all_connections!
9+
ActiveRecord::Base.establish_connection( Mysqlplus::Test::CONNECTION_SPEC )
10+
super
11+
end
12+
13+
test "should be able to raise exceptions from the background Thread" do
14+
assert_raises( StandardError ) do
15+
ActiveRecord::Deferrable::Result.new do
16+
raise StandardError
17+
end.to_s
18+
end
19+
end
20+
21+
test "should release the checked out connection for the background Thread at all times" do
22+
ActiveRecord::Base.connection_pool.expects(:release_connection).once
23+
ActiveRecord::Deferrable::Result.new do
24+
raise StandardError
25+
end
26+
end
27+
28+
test "should only block when an immediate result is required" do
29+
ActiveRecord::Deferrable::Result.any_instance.expects(:validate!).never
30+
ActiveRecord::Deferrable::Result.new do
31+
sleep(5)
32+
end
33+
end
34+
35+
end

0 commit comments

Comments
 (0)