diff options
author | fatkodima <fatkodima@rambler.ru> | 2017-12-14 17:05:13 +0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-01-22 13:54:00 -0500 |
commit | 4efbbc844b3cd5f76e0e24ae1a1f90bb57da3b18 (patch) | |
tree | a60bf3c0029f0176fe1fe8392fc25ccb4e7ed303 /activesupport/test/cache/behaviors | |
parent | c177bca26cbc08f8dfb1e3a68613a89e6a035783 (diff) | |
download | rails-4efbbc844b3cd5f76e0e24ae1a1f90bb57da3b18.tar.gz rails-4efbbc844b3cd5f76e0e24ae1a1f90bb57da3b18.tar.bz2 rails-4efbbc844b3cd5f76e0e24ae1a1f90bb57da3b18.zip |
Add support for connection pooling on RedisCacheStore
Diffstat (limited to 'activesupport/test/cache/behaviors')
-rw-r--r-- | activesupport/test/cache/behaviors/connection_pool_behavior.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/activesupport/test/cache/behaviors/connection_pool_behavior.rb b/activesupport/test/cache/behaviors/connection_pool_behavior.rb new file mode 100644 index 0000000000..500d51a134 --- /dev/null +++ b/activesupport/test/cache/behaviors/connection_pool_behavior.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +module ConnectionPoolBehavior + def test_connection_pool + emulating_latency do + begin + cache = ActiveSupport::Cache.lookup_store(store, pool_size: 2, pool_timeout: 1) + cache.clear + + threads = [] + + assert_raises Timeout::Error do + # One of the three threads will fail in 1 second because our pool size + # is only two. + 3.times do + threads << Thread.new do + cache.read("latency") + end + end + + threads.each(&:join) + end + ensure + threads.each(&:kill) + end + end + end + + def test_no_connection_pool + emulating_latency do + begin + cache = ActiveSupport::Cache.lookup_store(store) + cache.clear + + threads = [] + + assert_nothing_raised do + # Default connection pool size is 5, assuming 10 will make sure that + # the connection pool isn't used at all. + 10.times do + threads << Thread.new do + cache.read("latency") + end + end + + threads.each(&:join) + end + ensure + threads.each(&:kill) + end + end + end +end |