Browse files

Adding tests for creating cache configs of different types in sequenc…

…e. Demonstrates error explained in #596.
  • Loading branch information...
1 parent 864ea3d commit 1fee86f650cbc83e1490368c60ac32f14128ad96 @markstory markstory committed Apr 17, 2010
Showing with 41 additions and 1 deletion.
  1. +41 −1 cake/tests/cases/libs/cache/memcache.test.php
View
42 cake/tests/cases/libs/cache/memcache.test.php
@@ -61,7 +61,11 @@ function skip() {
function setUp() {
$this->_cacheDisable = Configure::read('Cache.disable');
Configure::write('Cache.disable', false);
- Cache::config('memcache', array('engine' => 'Memcache', 'prefix' => 'cake_'));
+ Cache::config('memcache', array(
+ 'engine' => 'Memcache',
+ 'prefix' => 'cake_',
+ 'duration' => 3600
+ ));
}
/**
* tearDown method
@@ -222,5 +226,41 @@ function testDeleteCache() {
$result = Cache::delete('delete_test');
$this->assertTrue($result);
}
+
+/**
+ * test that configurations don't conflict, when a file engine is declared after a memcache one.
+ *
+ * @return void
+ */
+ function testConfigurationConflict() {
+ Cache::config('long_memcache', array(
+ 'engine' => 'Memcache',
+ 'duration'=> '+2 seconds',
+ 'servers' => array('127.0.0.1:11211'),
+ ));
+ Cache::config('short_memcache', array(
+ 'engine' => 'Memcache',
+ 'duration'=> '+1 seconds',
+ 'servers' => array('127.0.0.1:11211'),
+ ));
+ Cache::config('some_file', array('engine' => 'File'));
+
+ $this->assertTrue(Cache::write('duration_test', 'yay', 'long_memcache'));
+ $this->assertTrue(Cache::write('short_duration_test', 'boo', 'short_memcache'));
+
+ $this->assertEqual(Cache::read('duration_test', 'long_memcache'), 'yay', 'Value was not read %s');
+ $this->assertEqual(Cache::read('short_duration_test', 'short_memcache'), 'boo', 'Value was not read %s');
+
+ sleep(1);
+ $this->assertEqual(Cache::read('duration_test', 'long_memcache'), 'yay', 'Value was not read %s');
+
+ sleep(2);
+ $this->assertFalse(Cache::read('short_duration_test', 'short_memcache'), 'Cache was not invalidated %s');
+ $this->assertFalse(Cache::read('duration_test', 'long_memcache'), 'Value did not expire %s');
+
+ Cache::delete('duration_test', 'long_memcache');
+ Cache::delete('short_duration_test', 'short_memcache');
+ }
+
}
?>

0 comments on commit 1fee86f

Please sign in to comment.