Skip to content

Commit c5c5155

Browse files
committed
Fix APC cache tests
- Using negative TTLs to force immediate expiration of keys, while convenient in tests, doesn't work consistently with APC and is an undocumented feature. Using a low TTL and sleep() is what garantees that it works for APC. See krakjoe/apcu#184 - The setting apc.use_request_time interferes with key expiration when running on CLI. Making sure it always has the sensible value for running the tests. See krakjoe/apcu#392
1 parent 6f521e9 commit c5c5155

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

test/unit/cache/sfAPCCacheTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@
3939
$cache = new sfAPCCache();
4040
$cache->initialize();
4141

42+
// make sure expired keys are dropped
43+
// see https://github.com/krakjoe/apcu/issues/391
44+
ini_set('apc.use_request_time', 0);
45+
4246
sfCacheDriverTests::launch($t, $cache);

test/unit/cache/sfCacheDriverTests.class.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ static public function launch($t, $cache)
1818
$t->is($cache->get('test'), $data, '->get() retrieves data form the cache');
1919
$t->is($cache->has('test'), true, '->has() returns true if the cache exists');
2020

21-
$t->ok($cache->set('test', $data, -10), '->set() takes a lifetime as its third argument');
21+
$t->ok($cache->set('test', $data, 1), '->set() takes a lifetime as its third argument');
22+
sleep(2);
2223
$t->is($cache->get('test', 'default'), 'default', '->get() returns the default value if cache has expired');
2324
$t->is($cache->has('test'), false, '->has() returns true if the cache exists');
2425

@@ -47,21 +48,24 @@ static public function launch($t, $cache)
4748
// ->clean()
4849
$t->diag('->clean()');
4950
$data = 'some random data to store in the cache system...';
50-
$cache->set('foo', $data, -10);
51+
$cache->set('foo', $data, 1);
52+
sleep(2);
5153
$cache->set('bar', $data, 86400);
5254

5355
$cache->clean(sfCache::OLD);
5456
$t->is($cache->has('foo'), false, '->clean() cleans old cache key if given the sfCache::OLD argument');
5557
$t->is($cache->has('bar'), true, '->clean() cleans old cache key if given the sfCache::OLD argument');
5658

57-
$cache->set('foo', $data, -10);
59+
$cache->set('foo', $data, 1);
60+
sleep(2);
5861
$cache->set('bar', $data, 86400);
5962

6063
$cache->clean(sfCache::ALL);
6164
$t->is($cache->has('foo'), false, '->clean() cleans all cache key if given the sfCache::ALL argument');
6265
$t->is($cache->has('bar'), false, '->clean() cleans all cache key if given the sfCache::ALL argument');
6366

64-
$cache->set('foo', $data, -10);
67+
$cache->set('foo', $data, 1);
68+
sleep(2);
6569
$cache->set('bar', $data, 86400);
6670

6771
$cache->clean();
@@ -128,7 +132,8 @@ static public function launch($t, $cache)
128132
$t->ok($delta >= $lifetime - 1 && $delta <= $lifetime, '->getTimeout() returns the timeout time for a given cache key');
129133
}
130134

131-
$cache->set('bar', 'foo', -10);
135+
$cache->set('bar', 'foo', 1);
136+
sleep(2);
132137
$t->is($cache->getTimeout('bar'), 0, '->getTimeout() returns the timeout time for a given cache key');
133138

134139
foreach (array(86400, 10) as $lifetime)
@@ -152,7 +157,8 @@ static public function launch($t, $cache)
152157
$t->ok($lastModified >= time() - 1 && $lastModified <= time(), '->getLastModified() returns the last modified time for a given cache key');
153158
}
154159

155-
$cache->set('bar', 'foo', -10);
160+
$cache->set('bar', 'foo', 1);
161+
sleep(2);
156162
$t->is($cache->getLastModified('bar'), 0, '->getLastModified() returns the last modified time for a given cache key');
157163

158164
foreach (array(86400, 10) as $lifetime)

0 commit comments

Comments
 (0)