[Pkg-owncloud-commits] [owncloud] 02/131: Test for chunk cache garbage collection
David Prévot
taffit at moszumanska.debian.org
Tue Aug 11 15:58:24 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag v8.1.1
in repository owncloud.
commit e48afaf33436857bc7efe255f72e58733819a1c8
Author: Vincent Petry <pvince81 at owncloud.com>
Date: Tue Jun 30 17:34:10 2015 +0200
Test for chunk cache garbage collection
---
tests/lib/cache/file.php | 94 +++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 89 insertions(+), 5 deletions(-)
diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php
index e31f84e..9400129 100644
--- a/tests/lib/cache/file.php
+++ b/tests/lib/cache/file.php
@@ -23,12 +23,22 @@
namespace Test\Cache;
class FileCache extends \Test_Cache {
- /** @var string */
+ /**
+ * @var string
+ * */
private $user;
- /** @var string */
+ /**
+ * @var string
+ * */
private $datadir;
- /** @var \OC\Files\Storage\Storage */
+ /**
+ * @var \OC\Files\Storage\Storage
+ * */
private $storage;
+ /**
+ * @var \OC\Files\View
+ * */
+ private $rootView;
function skip() {
//$this->skipUnless(OC_User::isLoggedIn());
@@ -59,13 +69,18 @@ class FileCache extends \Test_Cache {
\OC_User::setUserId('test');
//set up the users dir
- $rootView = new \OC\Files\View('');
- $rootView->mkdir('/test');
+ $this->rootView = new \OC\Files\View('');
+ $this->rootView->mkdir('/test');
$this->instance=new \OC\Cache\File();
+
+ // forces creation of cache folder for subsequent tests
+ $this->instance->set('hack', 'hack');
}
protected function tearDown() {
+ $this->instance->remove('hack', 'hack');
+
\OC_User::setUserId($this->user);
\OC_Config::setValue('cachedirectory', $this->datadir);
@@ -75,4 +90,73 @@ class FileCache extends \Test_Cache {
parent::tearDown();
}
+
+ private function setupMockStorage() {
+ $mockStorage = $this->getMock(
+ '\OC\Files\Storage\Local',
+ ['filemtime', 'unlink'],
+ [['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]]
+ );
+
+ \OC\Files\Filesystem::mount($mockStorage, array(), '/test/cache');
+
+ return $mockStorage;
+ }
+
+ public function testGarbageCollectOldKeys() {
+ $mockStorage = $this->setupMockStorage();
+
+ $mockStorage->expects($this->atLeastOnce())
+ ->method('filemtime')
+ ->will($this->returnValue(100));
+ $mockStorage->expects($this->once())
+ ->method('unlink')
+ ->with('key1')
+ ->will($this->returnValue(true));
+
+ $this->instance->set('key1', 'value1');
+ $this->instance->gc();
+ }
+
+ public function testGarbageCollectLeaveRecentKeys() {
+ $mockStorage = $this->setupMockStorage();
+
+ $mockStorage->expects($this->atLeastOnce())
+ ->method('filemtime')
+ ->will($this->returnValue(time() + 3600));
+ $mockStorage->expects($this->never())
+ ->method('unlink')
+ ->with('key1');
+ $this->instance->set('key1', 'value1');
+ $this->instance->gc();
+ }
+
+ public function lockExceptionProvider() {
+ return [
+ [new \OCP\Lock\LockedException('key1')],
+ [new \OCP\Files\LockNotAcquiredException('key1', 1)],
+ ];
+ }
+
+ /**
+ * @dataProvider lockExceptionProvider
+ */
+ public function testGarbageCollectIgnoreLockedKeys($testException) {
+ $mockStorage = $this->setupMockStorage();
+
+ $mockStorage->expects($this->atLeastOnce())
+ ->method('filemtime')
+ ->will($this->returnValue(100));
+ $mockStorage->expects($this->atLeastOnce())
+ ->method('unlink')
+ ->will($this->onConsecutiveCalls(
+ $this->throwException($testException),
+ $this->returnValue(true)
+ ));
+
+ $this->instance->set('key1', 'value1');
+ $this->instance->set('key2', 'value2');
+
+ $this->instance->gc();
+ }
}
--
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