Skip to content

Commit 8698f90

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 2a68033 commit 8698f90

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

.env.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
#
99
# To enable them in order to provide a fix, set to "on".
1010
#
11-
APC_ENABLE_CLI=off
11+
APC_ENABLE_CLI=on

test/unit/cache/sfAPCCacheTest.php

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

40+
// make sure expired keys are dropped
41+
// see https://github.com/krakjoe/apcu/issues/391
42+
ini_set('apc.use_request_time', 0);
43+
4044
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 @@ public static 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 @@ public static 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);
5152
$cache->set('bar', $data, 86400);
53+
sleep(2);
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();
@@ -126,7 +130,8 @@ public static function launch($t, $cache)
126130
$t->ok($delta >= $lifetime - 1 && $delta <= $lifetime, '->getTimeout() returns the timeout time for a given cache key');
127131
}
128132

129-
$cache->set('bar', 'foo', -10);
133+
$cache->set('bar', 'foo', 1);
134+
sleep(2);
130135
$t->is($cache->getTimeout('bar'), 0, '->getTimeout() returns the timeout time for a given cache key');
131136

132137
foreach (array(86400, 10) as $lifetime) {
@@ -148,7 +153,8 @@ public static function launch($t, $cache)
148153
$t->ok($lastModified >= time() - 1 && $lastModified <= time(), '->getLastModified() returns the last modified time for a given cache key');
149154
}
150155

151-
$cache->set('bar', 'foo', -10);
156+
$cache->set('bar', 'foo', 1);
157+
sleep(2);
152158
$t->is($cache->getLastModified('bar'), 0, '->getLastModified() returns the last modified time for a given cache key');
153159

154160
foreach (array(86400, 10) as $lifetime) {

0 commit comments

Comments
 (0)