diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2018-04-11 22:54:20 -0700 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2018-04-11 22:54:20 -0700 |
commit | 66df366268c4e5b17c9235b5a0c3aabcbd578e01 (patch) | |
tree | d530c63b9206755911665a84373501d5a266171d /activesupport/test/cache | |
parent | 84b1feeaff94a598b335c5d3f73c4f74f489a165 (diff) | |
download | rails-66df366268c4e5b17c9235b5a0c3aabcbd578e01.tar.gz rails-66df366268c4e5b17c9235b5a0c3aabcbd578e01.tar.bz2 rails-66df366268c4e5b17c9235b5a0c3aabcbd578e01.zip |
Fix `ActiveSupport::Cache` compression
(See previous commit for a description of the issue)
Diffstat (limited to 'activesupport/test/cache')
-rw-r--r-- | activesupport/test/cache/behaviors/cache_store_behavior.rb | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/activesupport/test/cache/behaviors/cache_store_behavior.rb b/activesupport/test/cache/behaviors/cache_store_behavior.rb index 84a3648ad0..0806665c27 100644 --- a/activesupport/test/cache/behaviors/cache_store_behavior.rb +++ b/activesupport/test/cache/behaviors/cache_store_behavior.rb @@ -162,7 +162,7 @@ module CacheStoreBehavior end def test_nil_with_compress_low_compress_threshold - assert_uncompressed(nil, compress: true, compress_threshold: 2) + assert_uncompressed(nil, compress: true, compress_threshold: 1) end def test_small_string_with_default_compression_settings @@ -178,7 +178,7 @@ module CacheStoreBehavior end def test_small_string_with_low_compress_threshold - assert_compressed(SMALL_STRING, compress: true, compress_threshold: 2) + assert_compressed(SMALL_STRING, compress: true, compress_threshold: 1) end def test_small_object_with_default_compression_settings @@ -229,6 +229,25 @@ module CacheStoreBehavior assert_uncompressed(LARGE_OBJECT, compress: true, compress_threshold: 1.megabyte) end + def test_incompressable_data + assert_uncompressed(nil, compress: true, compress_threshold: 1) + assert_uncompressed(true, compress: true, compress_threshold: 1) + assert_uncompressed(false, compress: true, compress_threshold: 1) + assert_uncompressed(0, compress: true, compress_threshold: 1) + assert_uncompressed(1.2345, compress: true, compress_threshold: 1) + assert_uncompressed("", compress: true, compress_threshold: 1) + + incompressible = nil + + # generate an incompressible string + loop do + incompressible = SecureRandom.bytes(1.kilobyte) + break if incompressible.bytesize < Zlib::Deflate.deflate(incompressible).bytesize + end + + assert_uncompressed(incompressible, compress: true, compress_threshold: 1) + end + def test_cache_key obj = Object.new def obj.cache_key |