Skip to content

Commit

Permalink
Adding tests for creating cache configs of different types in sequenc…
Browse files Browse the repository at this point in the history
…e. Demonstrates error explained in #596.
  • Loading branch information
markstory committed Apr 17, 2010
1 parent 864ea3d commit 1fee86f
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion cake/tests/cases/libs/cache/memcache.test.php
Expand Up @@ -61,7 +61,11 @@ function skip() {
function setUp() { function setUp() {
$this->_cacheDisable = Configure::read('Cache.disable'); $this->_cacheDisable = Configure::read('Cache.disable');
Configure::write('Cache.disable', false); 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 * tearDown method
Expand Down Expand Up @@ -222,5 +226,41 @@ function testDeleteCache() {
$result = Cache::delete('delete_test'); $result = Cache::delete('delete_test');
$this->assertTrue($result); $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.