]> git.mxchange.org Git - friendica.git/commitdiff
CacheLockDriverTest Fixings
authorPhilipp Holzer <admin@philipp.info>
Wed, 5 Sep 2018 20:16:23 +0000 (22:16 +0200)
committerPhilipp Holzer <admin@philipp.info>
Wed, 5 Sep 2018 20:16:23 +0000 (22:16 +0200)
- Changing test behaviour

tests/src/Core/Lock/ArrayCacheLockDriverTest.php
tests/src/Core/Lock/LockTest.php
tests/src/Core/Lock/MemcacheCacheLockDriverTest.php
tests/src/Core/Lock/MemcachedCacheLockDriverTest.php
tests/src/Core/Lock/RedisCacheLockDriverTest.php
tests/src/Core/Lock/SemaphoreLockDriverTest.php

index dc044f5c5c007ce5cd1e839cfbc2eb09fe908646..671341718b78168e5d15ffaadcd05d50747ed34d 100644 (file)
@@ -8,21 +8,9 @@ use Friendica\Core\Lock\CacheLockDriver;
 
 class ArrayCacheLockDriverTest extends LockTest
 {
-       /**
-        * @var \Friendica\Core\Cache\IMemoryCacheDriver
-        */
-       private $cache;
-
        protected function getInstance()
        {
-               $this->cache = new ArrayCache();
-               return new CacheLockDriver($this->cache);
-       }
-
-       public function tearDown()
-       {
-               $this->cache->clear();
-               parent::tearDown();
+               return new CacheLockDriver(new ArrayCache());
        }
 
        public function testLockTTL()
index 9698f0bdea42ef587a0692e5989db16c7b927c1b..a7bbea265f1a9fb9caf8e80ab3cc01b215864cb5 100644 (file)
@@ -19,6 +19,7 @@ abstract class LockTest extends DatabaseTest
        {
                parent::setUp();
                $this->instance = $this->getInstance();
+               $this->instance->releaseAll();
 
                // Reusable App object
                $this->app = BaseObject::getApp();
@@ -31,11 +32,18 @@ abstract class LockTest extends DatabaseTest
                Config::set('system', 'theme', 'system_theme');
        }
 
+       protected function tearDown()
+       {
+               parent::tearDown();
+               $this->instance->releaseAll();
+       }
+
        /**
         * @small
         */
        public function testLock() {
-               $this->instance->acquireLock('foo', 1);
+               $this->assertFalse($this->instance->isLocked('foo'));
+               $this->assertTrue($this->instance->acquireLock('foo', 1));
                $this->assertTrue($this->instance->isLocked('foo'));
                $this->assertFalse($this->instance->isLocked('bar'));
        }
@@ -44,7 +52,8 @@ abstract class LockTest extends DatabaseTest
         * @small
         */
        public function testDoubleLock() {
-               $this->instance->acquireLock('foo', 1);
+               $this->assertFalse($this->instance->isLocked('foo'));
+               $this->assertTrue($this->instance->acquireLock('foo', 1));
                $this->assertTrue($this->instance->isLocked('foo'));
                // We already locked it
                $this->assertTrue($this->instance->acquireLock('foo', 1));
@@ -54,7 +63,8 @@ abstract class LockTest extends DatabaseTest
         * @small
         */
        public function testReleaseLock() {
-               $this->instance->acquireLock('foo', 1);
+               $this->assertFalse($this->instance->isLocked('foo'));
+               $this->assertTrue($this->instance->acquireLock('foo', 1));
                $this->assertTrue($this->instance->isLocked('foo'));
                $this->instance->releaseLock('foo');
                $this->assertFalse($this->instance->isLocked('foo'));
@@ -64,9 +74,9 @@ abstract class LockTest extends DatabaseTest
         * @small
         */
        public function testReleaseAll() {
-               $this->instance->acquireLock('foo', 1);
-               $this->instance->acquireLock('bar', 1);
-               $this->instance->acquireLock('nice', 1);
+               $this->assertTrue($this->instance->acquireLock('foo', 1));
+               $this->assertTrue($this->instance->acquireLock('bar', 1));
+               $this->assertTrue($this->instance->acquireLock('nice', 1));
 
                $this->assertTrue($this->instance->isLocked('foo'));
                $this->assertTrue($this->instance->isLocked('bar'));
@@ -83,9 +93,12 @@ abstract class LockTest extends DatabaseTest
         * @small
         */
        public function testReleaseAfterUnlock() {
-               $this->instance->acquireLock('foo', 1);
-               $this->instance->acquireLock('bar', 1);
-               $this->instance->acquireLock('nice', 1);
+               $this->assertFalse($this->instance->isLocked('foo'));
+               $this->assertFalse($this->instance->isLocked('bar'));
+               $this->assertFalse($this->instance->isLocked('nice'));
+               $this->assertTrue($this->instance->acquireLock('foo', 1));
+               $this->assertTrue($this->instance->acquireLock('bar', 1));
+               $this->assertTrue($this->instance->acquireLock('nice', 1));
 
                $this->instance->releaseLock('foo');
 
@@ -103,10 +116,12 @@ abstract class LockTest extends DatabaseTest
         * @medium
         */
        function testLockTTL() {
+               $this->assertFalse($this->instance->isLocked('foo'));
+               $this->assertFalse($this->instance->isLocked('bar'));
 
                // TODO [nupplaphil] - Because of the Datetime-Utils for the database, we have to wait a FULL second between the checks to invalidate the db-locks/cache
-               $this->instance->acquireLock('foo', 1, 1);
-               $this->instance->acquireLock('bar', 1, 3);
+               $this->assertTrue($this->instance->acquireLock('foo', 2, 1));
+               $this->assertTrue($this->instance->acquireLock('bar', 2, 3));
 
                $this->assertTrue($this->instance->isLocked('foo'));
                $this->assertTrue($this->instance->isLocked('bar'));
index c54cf9c59941ab4ce79441d2a9a9b4218bee58e5..ca9b9b46391ae3cf3320b26461b9e5f34a8de187 100644 (file)
@@ -3,7 +3,6 @@
 
 namespace Friendica\Test\src\Core\Lock;
 
-
 use Friendica\Core\Cache\CacheDriverFactory;
 use Friendica\Core\Lock\CacheLockDriver;
 
@@ -12,20 +11,8 @@ use Friendica\Core\Lock\CacheLockDriver;
  */
 class MemcacheCacheLockDriverTest extends LockTest
 {
-       /**
-        * @var \Friendica\Core\Cache\IMemoryCacheDriver
-        */
-       private $cache;
-
        protected function getInstance()
        {
-               $this->cache = CacheDriverFactory::create('memcache');
-               return new CacheLockDriver($this->cache);
-       }
-
-       public function tearDown()
-       {
-               $this->cache->clear();
-               parent::tearDown();
+               return new CacheLockDriver(CacheDriverFactory::create('memcache'));
        }
 }
index 27886261b2591080ed94a7c0bfc5438520fa38c6..71311d5baa36d5f6fa53022daf255730c73b82a6 100644 (file)
@@ -3,7 +3,6 @@
 
 namespace Friendica\Test\src\Core\Lock;
 
-
 use Friendica\Core\Cache\CacheDriverFactory;
 use Friendica\Core\Lock\CacheLockDriver;
 
@@ -12,20 +11,8 @@ use Friendica\Core\Lock\CacheLockDriver;
  */
 class MemcachedCacheLockDriverTest extends LockTest
 {
-       /**
-        * @var \Friendica\Core\Cache\IMemoryCacheDriver
-        */
-       private $cache;
-
        protected function getInstance()
        {
-               $this->cache = CacheDriverFactory::create('memcached');
-               return new CacheLockDriver($this->cache);
-       }
-
-       public function tearDown()
-       {
-               $this->cache->clear();
-               parent::tearDown();
+               return new CacheLockDriver(CacheDriverFactory::create('memcached'));
        }
 }
index eaafbf4e443007e505c55f474f7a8c67a978d232..43cedb9cbc323eaa2855f04b6e27cecac2c1e92a 100644 (file)
@@ -3,7 +3,6 @@
 
 namespace Friendica\Test\src\Core\Lock;
 
-
 use Friendica\Core\Cache\CacheDriverFactory;
 use Friendica\Core\Lock\CacheLockDriver;
 
@@ -12,21 +11,9 @@ use Friendica\Core\Lock\CacheLockDriver;
  */
 class RedisCacheLockDriverTest extends LockTest
 {
-       /**
-        * @var \Friendica\Core\Cache\IMemoryCacheDriver
-        */
-       private $cache;
-
        protected function getInstance()
        {
-               $this->cache = CacheDriverFactory::create('redis');
-               return new CacheLockDriver($this->cache);
+               return new CacheLockDriver(CacheDriverFactory::create('redis'));
 
        }
-
-       public function tearDown()
-       {
-               $this->cache->clear();
-               parent::tearDown();
-       }
 }
index cd4b9157334a1da5119e2adc9d889229ddd7e64d..39f0763fb13c0b015c5c1a85677a42431879fa1e 100644 (file)
@@ -2,26 +2,13 @@
 
 namespace Friendica\Test\src\Core\Lock;
 
-
 use Friendica\Core\Lock\SemaphoreLockDriver;
 
 class SemaphoreLockDriverTest extends LockTest
 {
-       /**
-        * @var \Friendica\Core\Lock\SemaphoreLockDriver
-        */
-       private $semaphoreLockDriver;
-
        protected function getInstance()
        {
-               $this->semaphoreLockDriver = new SemaphoreLockDriver();
-               return $this->semaphoreLockDriver;
-       }
-
-       public function tearDown()
-       {
-               $this->semaphoreLockDriver->releaseAll();
-               parent::tearDown();
+               return new SemaphoreLockDriver();
        }
 
        function testLockTTL()