[Pkg-owncloud-commits] [owncloud] 76/118: Add unit tests for gc() for \OC\Cache\FileGlobalGC

David Prévot taffit at moszumanska.debian.org
Fri Mar 27 22:13:15 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 58ad3fac063ef960bda97fe2cbc2e2f64fc6ad4d
Author: Robin McCorkell <rmccorkell at karoshi.org.uk>
Date:   Wed Mar 18 16:19:04 2015 +0000

    Add unit tests for gc() for \OC\Cache\FileGlobalGC
---
 lib/private/cache/fileglobalgc.php |  6 ++++--
 tests/lib/cache/fileglobalgc.php   | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/lib/private/cache/fileglobalgc.php b/lib/private/cache/fileglobalgc.php
index 0bd3f73..b07e886 100644
--- a/lib/private/cache/fileglobalgc.php
+++ b/lib/private/cache/fileglobalgc.php
@@ -6,6 +6,9 @@ use OC\BackgroundJob\Job;
 use OCP\IConfig;
 
 class FileGlobalGC extends Job {
+	// only do cleanup every 5 minutes
+	const CLEANUP_TTL_SEC = 300;
+
 	public function run($argument) {
 		$this->gc(\OC::$server->getConfig(), $this->getCacheDir());
 	}
@@ -39,8 +42,7 @@ class FileGlobalGC extends Job {
 	public function gc(IConfig $config, $cacheDir) {
 		$lastRun = $config->getAppValue('core', 'global_cache_gc_lastrun', 0);
 		$now = time();
-		if (($now - $lastRun) < 300) {
-			// only do cleanup every 5 minutes
+		if (($now - $lastRun) < self::CLEANUP_TTL_SEC) {
 			return;
 		}
 		$config->setAppValue('core', 'global_cache_gc_lastrun', $now);
diff --git a/tests/lib/cache/fileglobalgc.php b/tests/lib/cache/fileglobalgc.php
index 0b0a4cb..4f03253 100644
--- a/tests/lib/cache/fileglobalgc.php
+++ b/tests/lib/cache/fileglobalgc.php
@@ -70,4 +70,38 @@ class FileGlobalGC extends TestCase {
 		mkdir($this->cacheDir . 'asd');
 		$this->assertEquals([$this->cacheDir . 'foo'], $this->gc->getExpiredPaths($this->cacheDir, $time));
 	}
+
+	public function testGcUnlink() {
+		$time = time();
+		$this->addCacheFile('foo', $time - 10);
+		$this->addCacheFile('bar', $time - 10);
+		$this->addCacheFile('asd', $time + 10);
+
+		$config = $this->getMock('\OCP\IConfig');
+		$config->expects($this->once())
+			->method('getAppValue')
+			->with('core', 'global_cache_gc_lastrun', 0)
+			->willReturn($time - \OC\Cache\FileGlobalGC::CLEANUP_TTL_SEC - 1);
+		$config->expects($this->once())
+			->method('setAppValue');
+
+		$this->gc->gc($config, $this->cacheDir);
+		$this->assertFileNotExists($this->cacheDir . 'foo');
+		$this->assertFileNotExists($this->cacheDir . 'bar');
+		$this->assertFileExists($this->cacheDir . 'asd');
+	}
+
+	public function testGcLastRun() {
+		$time = time();
+
+		$config = $this->getMock('\OCP\IConfig');
+		$config->expects($this->once())
+			->method('getAppValue')
+			->with('core', 'global_cache_gc_lastrun', 0)
+			->willReturn($time);
+		$config->expects($this->never())
+			->method('setAppValue');
+
+		$this->gc->gc($config, $this->cacheDir);
+	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list