Skip to content

Commit 22ca9c0

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 22ca9c0

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

.env.dist

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,3 @@
33
#
44
# Copy to `.env` in order to use it.
55
#
6-
7-
# APC test are disabled.
8-
#
9-
# To enable them in order to provide a fix, set to "on".
10-
#
11-
APC_ENABLE_CLI=off

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ services:
3131
echo 'short_open_tag = off'
3232
echo 'magic_quotes_gpc = off'
3333
echo 'date.timezone = "UTC"'
34-
echo 'apc.enable_cli = ${APC_ENABLE_CLI-off}'
34+
echo 'apc.enable_cli = on'
3535
echo 'apc.use_request_time = 0'
3636
} | tee -a /usr/local/lib/php.ini
3737
@@ -60,7 +60,7 @@ services:
6060
echo 'short_open_tag = off'
6161
echo 'magic_quotes_gpc = off'
6262
echo 'date.timezone = "UTC"'
63-
echo 'apc.enable_cli = ${APC_ENABLE_CLI-off}'
63+
echo 'apc.enable_cli = on'
6464
echo 'apc.use_request_time = 0'
6565
} | tee -a /usr/local/etc/php/php.ini
6666

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)