Skip to content

Commit 2f65345

Browse files
milodg
authored andcommitted
Tests: fixed CacheStorage's sliding tests [Closing nette/nette#958]
These tests failed on Travis-ci.org accidentally. It's because sliding interval was so tight. I verified, that sliding functionality is working well in both cases (MemcachedStorage, FileStorage). The expiration of data is properly prolonged on every reading. But there is a potential weak place. Cache::completeDependencies() converts expiration time to relative amount of seconds. When user sets expiration at time() + 2, until Cache::completeDependencies() runs, time() value increase. So, expiration time is decreased by 1 second in consequence. I guess, this is a reason why tests failed on Travis (virtual server, time jitter, I/O rush). I hope, this feature needn't be fixed, Cache is not permanent data storage. And nobody complain.
1 parent f66d22e commit 2f65345

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

tests/Caching/FileStorage.sliding.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,22 @@ $cache = new Cache(new FileStorage(TEMP_DIR));
2424

2525
// Writing cache...
2626
$cache->save($key, $value, array(
27-
Cache::EXPIRATION => time() + 2,
27+
Cache::EXPIRATION => time() + 3,
2828
Cache::SLIDING => TRUE,
2929
));
3030

3131

32-
for($i = 0; $i < 3; $i++) {
32+
for ($i = 0; $i < 5; $i++) {
3333
// Sleeping 1 second
3434
sleep(1);
3535
clearstatcache();
36+
3637
Assert::true( isset($cache[$key]), 'Is cached?' );
3738

3839
}
3940

4041
// Sleeping few seconds...
41-
sleep(3);
42+
sleep(5);
4243
clearstatcache();
4344

4445
Assert::false( isset($cache[$key]), 'Is cached?' );

tests/Caching/Memcached.sliding.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@ $cache = new Cache(new MemcachedStorage('localhost'));
3030

3131
// Writing cache...
3232
$cache->save($key, $value, array(
33-
Cache::EXPIRATION => time() + 2,
33+
Cache::EXPIRATION => time() + 3,
3434
Cache::SLIDING => TRUE,
3535
));
3636

3737

38-
for($i = 0; $i < 3; $i++) {
38+
for ($i = 0; $i < 5; $i++) {
3939
// Sleeping 1 second
4040
sleep(1);
41+
4142
Assert::true( isset($cache[$key]), 'Is cached?' );
4243

4344
}
4445

4546
// Sleeping few seconds...
46-
sleep(4);
47+
sleep(5);
4748

4849
Assert::false( isset($cache[$key]), 'Is cached?' );

0 commit comments

Comments
 (0)