aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-10-21 12:42:06 -0700
committerJosé Valim <jose.valim@gmail.com>2011-10-21 12:42:06 -0700
commit79d01a8f16e20c556a086a2f07e3ccb4400f9819 (patch)
tree28e31a1c0a15d4ec1935f914668e1b912cbc276d /activesupport/test
parentb838570bd69ff13d677fb43e79f10d6f3168c696 (diff)
parentec93f363cab7270c1469b420a52a21e306a89c30 (diff)
downloadrails-79d01a8f16e20c556a086a2f07e3ccb4400f9819.tar.gz
rails-79d01a8f16e20c556a086a2f07e3ccb4400f9819.tar.bz2
rails-79d01a8f16e20c556a086a2f07e3ccb4400f9819.zip
Merge pull request #3395 from bdurand/fix_file_store_cleanup
Fix ActiveSupport::Cache::FileStore.cleanup to actually work.
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/caching_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index cb5362525f..1b2f6d061c 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -557,6 +557,29 @@ class FileStoreTest < ActiveSupport::TestCase
key = @cache_with_pathname.send(:key_file_path, "views/index?id=1")
assert_equal "views/index?id=1", @cache_with_pathname.send(:file_path_key, key)
end
+
+ def test_cleanup_with_not_accessed_in
+ @cache.write(1, "aaaaaaaaaa")
+ @cache.write(2, "bbbbbbbbbb")
+ @cache.write(3, "cccccccccc")
+ sleep(2)
+ @cache.read(2)
+ @cache.cleanup(:not_accessed_in => 1)
+ assert_equal false, @cache.exist?(1)
+ assert_equal true, @cache.exist?(2)
+ assert_equal false, @cache.exist?(3)
+ end
+
+ def test_cleanup_with_expired_only
+ @cache.write(1, "aaaaaaaaaa", :expires_in => 0.001)
+ @cache.write(2, "bbbbbbbbbb")
+ @cache.write(3, "cccccccccc", :expires_in => 0.001)
+ sleep(0.002)
+ @cache.cleanup(:expired_only => 0.001)
+ assert_equal false, @cache.exist?(1)
+ assert_equal true, @cache.exist?(2)
+ assert_equal false, @cache.exist?(3)
+ end
# Because file systems have a maximum filename size, filenames > max size should be split in to directories
# If filename is 'AAAAB', where max size is 4, the returned path should be AAAA/B
@@ -646,6 +669,17 @@ class MemoryStoreTest < ActiveSupport::TestCase
assert_equal true, @cache.exist?(2)
assert_equal false, @cache.exist?(1)
end
+
+ def test_cleanup_removes_expired_entries
+ @cache.write(1, "aaaaaaaaaa", :expires_in => 0.001)
+ @cache.write(2, "bbbbbbbbbb")
+ @cache.write(3, "cccccccccc", :expires_in => 0.001)
+ sleep(0.002)
+ @cache.cleanup
+ assert_equal false, @cache.exist?(1)
+ assert_equal true, @cache.exist?(2)
+ assert_equal false, @cache.exist?(3)
+ end
end
uses_memcached 'memcached backed store' do