diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-09-18 17:02:18 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-09-18 17:02:18 +0200 |
commit | bbf128f1b21a335f9b32ffa919890ccbab29204f (patch) | |
tree | d8825e518534053f205ea59332887b37dca4dd76 /tests | |
parent | 3325fb4cdd2982b442558efbae4b068739517bc9 (diff) | |
parent | e9b1aa603715fcbefdef8cb96b042fa2f0348bf1 (diff) | |
download | nextcloud-server-bbf128f1b21a335f9b32ffa919890ccbab29204f.tar.gz nextcloud-server-bbf128f1b21a335f9b32ffa919890ccbab29204f.zip |
Merge pull request #19098 from owncloud/db-lock-no-transaction
Remove the need for the transaction in the database locking backend
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/lock/dblockingprovider.php | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/tests/lib/lock/dblockingprovider.php b/tests/lib/lock/dblockingprovider.php index fd6550d9c47..2360052b4a0 100644 --- a/tests/lib/lock/dblockingprovider.php +++ b/tests/lib/lock/dblockingprovider.php @@ -21,7 +21,13 @@ namespace Test\Lock; +use OCP\Lock\ILockingProvider; + class DBLockingProvider extends LockingProvider { + /** + * @var \OC\Lock\DBLockingProvider + */ + protected $instance; /** * @var \OCP\IDBConnection @@ -29,15 +35,63 @@ class DBLockingProvider extends LockingProvider { private $connection; /** + * @var \OCP\AppFramework\Utility\ITimeFactory + */ + private $timeFactory; + + private $currentTime; + + public function setUp() { + $this->currentTime = time(); + $this->timeFactory = $this->getMock('\OCP\AppFramework\Utility\ITimeFactory'); + $this->timeFactory->expects($this->any()) + ->method('getTime') + ->will($this->returnCallback(function () { + return $this->currentTime; + })); + parent::setUp(); + } + + /** * @return \OCP\Lock\ILockingProvider */ protected function getInstance() { $this->connection = \OC::$server->getDatabaseConnection(); - return new \OC\Lock\DBLockingProvider($this->connection, \OC::$server->getLogger()); + return new \OC\Lock\DBLockingProvider($this->connection, \OC::$server->getLogger(), $this->timeFactory); } public function tearDown() { $this->connection->executeQuery('DELETE FROM `*PREFIX*file_locks`'); parent::tearDown(); } + + public function testCleanEmptyLocks() { + $this->currentTime = 100; + $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); + $this->instance->acquireLock('asd', ILockingProvider::LOCK_EXCLUSIVE); + + $this->currentTime = 200; + $this->instance->acquireLock('bar', ILockingProvider::LOCK_EXCLUSIVE); + $this->instance->changeLock('asd', ILockingProvider::LOCK_SHARED); + + $this->currentTime = 150 + \OC\Lock\DBLockingProvider::TTL; + + $this->assertEquals(3, $this->getLockEntryCount()); + + $this->instance->cleanEmptyLocks(); + + $this->assertEquals(3, $this->getLockEntryCount()); + + $this->instance->releaseAll(); + + $this->instance->cleanEmptyLocks(); + + $this->assertEquals(2, $this->getLockEntryCount()); + } + + private function getLockEntryCount() { + $query = $this->connection->prepare('SELECT count(*) FROM `*PREFIX*file_locks`'); + $query->execute(); + return $query->fetchColumn(); + } } |