]> git.mxchange.org Git - friendica.git/commitdiff
LockDriverFixings
authorPhilipp Holzer <admin@philipp.info>
Thu, 6 Sep 2018 06:11:18 +0000 (08:11 +0200)
committerPhilipp Holzer <admin@philipp.info>
Thu, 6 Sep 2018 06:11:18 +0000 (08:11 +0200)
- release Locks in case of failures
- adding some cache tests

src/Core/Cache/ArrayCache.php
src/Core/Worker.php
src/Model/Item.php
tests/src/Core/Cache/CacheTest.php

index b1982871487c241830dea1d70e5eb6a0750cd2ac..d1302c1d6ec327d5f04a0a570b58c4da747954b5 100644 (file)
@@ -53,6 +53,11 @@ class ArrayCache extends AbstractCacheDriver implements IMemoryCacheDriver
         */
        public function clear($outdated = true)
        {
+               // Array doesn't support TTL so just don't delete something
+               if ($outdated) {
+                       return true;
+               }
+
                $this->cachedData = [];
                return true;
        }
index 9dd973728dcbfb6c8256883d538c624e62b50855..3400f00ae1755229a24a20e16fc6844f1c7592c5 100644 (file)
@@ -117,12 +117,14 @@ class Worker
                                // Count active workers and compare them with a maximum value that depends on the load
                                if (self::tooMuchWorkers()) {
                                        logger('Active worker limit reached, quitting.', LOGGER_DEBUG);
+                                       Lock::release('worker');
                                        return;
                                }
 
                                // Check free memory
                                if ($a->min_memory_reached()) {
                                        logger('Memory limit reached, quitting.', LOGGER_DEBUG);
+                                       Lock::release('worker');
                                        return;
                                }
                                Lock::release('worker');
index d235f0a7f96bab562745c0be47b04c5131b8e5e5..10c705a9959b6e2b4185c3f6887aa727abaefacd 100644 (file)
@@ -1936,6 +1936,7 @@ class Item extends BaseObject
                } else {
                        // This shouldn't happen.
                        logger('Could not insert activity for URI ' . $item['uri'] . ' - should not happen');
+                       Lock::release('item_insert_activity');
                        return false;
                }
                if ($locked) {
index 105142f0b74250eb048d10a87806d10a78b3dd8c..5c56c2072f4f13add69b2552cc03531fedadab7f 100644 (file)
@@ -81,18 +81,32 @@ abstract class CacheTest extends DatabaseTest
                        '3_value1' => $this->instance->get('3_value1'),
                ]);
 
+               $this->assertTrue($this->instance->clear());
+
+               $this->assertEquals([
+                       '1_value1' => 'ipsum lorum1',
+                       '1_value2' => 'ipsum lorum2',
+                       '2_value1' => 'ipsum lorum3',
+                       '3_value1' => 'ipsum lorum4',
+               ], [
+                       '1_value1' => $this->instance->get('1_value1'),
+                       '1_value2' => $this->instance->get('1_value2'),
+                       '2_value1' => $this->instance->get('2_value1'),
+                       '3_value1' => $this->instance->get('3_value1'),
+               ]);
+
                $this->assertTrue($this->instance->clear(false));
 
                $this->assertEquals([
                        '1_value1' => null,
                        '1_value2' => null,
-                       '2_value1' => null,
-                       '3_value1' => null,
+                       '2_value3' => null,
+                       '3_value4' => null,
                ], [
                        '1_value1' => $this->instance->get('1_value1'),
                        '1_value2' => $this->instance->get('1_value2'),
-                       '2_value1' => $this->instance->get('2_value1'),
-                       '3_value1' => $this->instance->get('3_value1'),
+                       '2_value3' => $this->instance->get('2_value3'),
+                       '3_value4' => $this->instance->get('3_value4'),
                ]);
        }