diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-07-17 14:43:08 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-07-17 14:43:08 -0700 |
commit | 8f9702db5cdd2afeca267f883980d4dcd4659edc (patch) | |
tree | 526b62a0565fbf89decc9148f3e935f313c6dc06 /activesupport/test | |
parent | 636e6b7138864ceb1e309939cd879e710b287f3e (diff) | |
parent | 7359597004a63277851acbc87f0267d3d63e17eb (diff) | |
download | rails-8f9702db5cdd2afeca267f883980d4dcd4659edc.tar.gz rails-8f9702db5cdd2afeca267f883980d4dcd4659edc.tar.bz2 rails-8f9702db5cdd2afeca267f883980d4dcd4659edc.zip |
Merge branch 'master' of git@github.com:rails/rails
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/caching_test.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index f3220d27aa..0af4251962 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -70,3 +70,70 @@ uses_mocha 'high-level cache store tests' do end end end + +class ThreadSafetyCacheStoreTest < Test::Unit::TestCase + def setup + @cache = ActiveSupport::Cache.lookup_store(:memory_store).threadsafe! + @cache.write('foo', 'bar') + + # No way to have mocha proxy to the original method + @mutex = @cache.instance_variable_get(:@mutex) + @mutex.instance_eval %( + def calls; @calls; end + def synchronize + @calls ||= 0 + @calls += 1 + yield + end + ) + end + + def test_read_is_synchronized + assert_equal 'bar', @cache.read('foo') + assert_equal 1, @mutex.calls + end + + def test_write_is_synchronized + @cache.write('foo', 'baz') + assert_equal 'baz', @cache.read('foo') + assert_equal 2, @mutex.calls + end + + def test_delete_is_synchronized + assert_equal 'bar', @cache.read('foo') + @cache.delete('foo') + assert_equal nil, @cache.read('foo') + assert_equal 3, @mutex.calls + end + + def test_delete_matched_is_synchronized + assert_equal 'bar', @cache.read('foo') + @cache.delete_matched(/foo/) + assert_equal nil, @cache.read('foo') + assert_equal 3, @mutex.calls + end + + def test_fetch_is_synchronized + assert_equal 'bar', @cache.fetch('foo') { 'baz' } + assert_equal 'fu', @cache.fetch('bar') { 'fu' } + assert_equal 3, @mutex.calls + end + + def test_exist_is_synchronized + assert @cache.exist?('foo') + assert !@cache.exist?('bar') + assert_equal 2, @mutex.calls + end + + def test_increment_is_synchronized + @cache.write('foo_count', 1) + assert_equal 2, @cache.increment('foo_count') + assert_equal 4, @mutex.calls + end + + def test_decrement_is_synchronized + @cache.write('foo_count', 1) + assert_equal 0, @cache.decrement('foo_count') + assert_equal 4, @mutex.calls + end +end |