From 1d08b2cb2a68c53d867110a8c3fb99cb1cb440fc Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 24 May 2021 13:29:57 +0200 Subject: [PATCH 1/5] Fix tests --- .codecov.yml | 6 +++--- tests/phpunit.xml | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index 0c54747c9..4d2921cc4 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -8,7 +8,7 @@ coverage: round: down range: "70...100" status: - project: off - patch: off + project: false + patch: false -comment: off +comment: false diff --git a/tests/phpunit.xml b/tests/phpunit.xml index c4197d3e4..0c5ad458a 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -8,7 +8,7 @@ timeoutForLargeTests="900"> functional/ - include/ + legacy/ src/ @@ -16,14 +16,14 @@ .. - config/ - doc/ - images/ - library/ - spec/ - tests/ - view/ - vendor/ + ../config/ + ../doc/ + ../images/ + ../library/ + ../spec/ + ../tests/ + ../view/ + ../vendor/ From 10e8c5594d54e8e1e4014b02372e4ffc6a3ab23a Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 24 May 2021 13:47:02 +0200 Subject: [PATCH 2/5] Fix API tests --- tests/legacy/ApiTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 837b7409b..4a1839f8c 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -2266,6 +2266,7 @@ class ApiTest extends FixtureTest [ 'network' => 'feed', 'title' => 'item_title', + 'uri-id' => 1, // We need a long string to test that it is correctly cut 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' . 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' . @@ -2308,12 +2309,13 @@ class ApiTest extends FixtureTest [ 'network' => 'feed', 'title' => 'item_title', + 'uri-id' => 1, 'body' => '', 'plink' => 'item_plink' ] ); - self::assertEquals('item_title', $result['text']); - self::assertEquals('

item_title


item_plink', $result['html']); + self::assertEquals("item_title\n\nParent status", $result['text']); + self::assertEquals('

item_title


Parent statusitem_plink', $result['html']); } /** @@ -2325,8 +2327,9 @@ class ApiTest extends FixtureTest { $result = api_convert_item( [ - 'title' => 'item_title', - 'body' => 'item_title item_body' + 'title' => 'item_title', + 'body' => 'item_title item_body', + 'uri-id' => 1, ] ); self::assertEquals('item_title item_body', $result['text']); From ea4b066df37ef4aa7cf068b2e74b11439026fae3 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 24 May 2021 20:30:56 +0200 Subject: [PATCH 3/5] Fix DBA::lock() testability because of "autocommits" --- tests/DatabaseTestTrait.php | 2 ++ tests/Util/Database/ExtendedPDO.php | 28 +++++++++--------- tests/Util/Database/StaticDatabase.php | 40 ++++++++++++++++++-------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/tests/DatabaseTestTrait.php b/tests/DatabaseTestTrait.php index 7d255c693..eae5ce2ac 100644 --- a/tests/DatabaseTestTrait.php +++ b/tests/DatabaseTestTrait.php @@ -34,6 +34,8 @@ trait DatabaseTestTrait StaticDatabase::statConnect($_SERVER); // Rollbacks every DB usage (in case the test couldn't call tearDown) StaticDatabase::statRollback(); + // Rollback the first, outer transaction just 2 be sure + StaticDatabase::getGlobConnection()->rollBack(); // Start the first, outer transaction StaticDatabase::getGlobConnection()->beginTransaction(); } diff --git a/tests/Util/Database/ExtendedPDO.php b/tests/Util/Database/ExtendedPDO.php index 6a59d2aee..c9ce42b3e 100644 --- a/tests/Util/Database/ExtendedPDO.php +++ b/tests/Util/Database/ExtendedPDO.php @@ -69,7 +69,7 @@ class ExtendedPDO extends PDO { if($this->_transactionDepth <= 0 || !$this->hasSavepoint()) { parent::beginTransaction(); - $this->_transactionDepth = $this->_transactionDepth < 0 ? 0 : $this->_transactionDepth; + $this->_transactionDepth = 0; } else { $this->exec("SAVEPOINT LEVEL{$this->_transactionDepth}"); } @@ -84,14 +84,15 @@ class ExtendedPDO extends PDO */ public function commit() { + // We don't want to "really" commit something, so skip the most outer hierarchy + if ($this->_transactionDepth <= 1 && $this->hasSavepoint()) { + $this->_transactionDepth = $this->_transactionDepth <= 0 ? 0 : 1; + return true; + } + $this->_transactionDepth--; - if($this->_transactionDepth <= 0 || !$this->hasSavepoint()) { - parent::commit(); - $this->_transactionDepth = $this->_transactionDepth < 0 ? 0 : $this->_transactionDepth; - } else { - $this->exec("RELEASE SAVEPOINT LEVEL{$this->_transactionDepth}"); - } + $this->exec("RELEASE SAVEPOINT LEVEL{$this->_transactionDepth}"); } /** @@ -102,14 +103,15 @@ class ExtendedPDO extends PDO */ public function rollBack() { - if ($this->_transactionDepth <= 0) { - throw new PDOException('Rollback error : There is no transaction started'); - } - $this->_transactionDepth--; - if($this->_transactionDepth == 0 || !$this->hasSavepoint()) { - parent::rollBack(); + if($this->_transactionDepth <= 0 || !$this->hasSavepoint()) { + $this->_transactionDepth = 0; + try { + parent::rollBack(); + } catch (PDOException $e) { + // this shouldn't happen, but it does ... + } } else { $this->exec("ROLLBACK TO SAVEPOINT LEVEL{$this->_transactionDepth}"); } diff --git a/tests/Util/Database/StaticDatabase.php b/tests/Util/Database/StaticDatabase.php index 48b392978..3bf6396a9 100644 --- a/tests/Util/Database/StaticDatabase.php +++ b/tests/Util/Database/StaticDatabase.php @@ -39,6 +39,9 @@ class StaticDatabase extends Database */ private static $staticConnection; + /** @var bool */ + private $_locked = false; + /** * Override the behaviour of connect, due there is just one, static connection at all * @@ -77,6 +80,31 @@ class StaticDatabase extends Database return true; } + /** Mock for locking tables */ + public function lock($table) + { + if ($this->_locked) { + return false; + } + + $this->in_transaction = true; + $this->_locked = true; + + return true; + } + + /** Mock for unlocking tables */ + public function unlock() + { + // See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html + $this->performCommit(); + + $this->in_transaction = false; + $this->_locked = false; + + return true; + } + /** * Does a commit * @@ -163,18 +191,6 @@ class StaticDatabase extends Database return self::$staticConnection; } - /** - * Perform a global commit for every nested transaction of the static connection - */ - public static function statCommit() - { - if (isset(self::$staticConnection)) { - while (self::$staticConnection->getTransactionDepth() > 0) { - self::$staticConnection->commit(); - } - } - } - /** * Perform a global rollback for every nested transaction of the static connection */ From 6428e417dbfb96227d79bafd4bb1770d85ef8061 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 24 May 2021 20:31:10 +0200 Subject: [PATCH 4/5] Split drone steps for readability --- .drone.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.drone.yml b/.drone.yml index ec9963135..d49840fdc 100644 --- a/.drone.yml +++ b/.drone.yml @@ -67,6 +67,11 @@ type: docker name: php7.3-mariadb steps: + - name: Composer install + image: friendicaci/php7.4:php7.4.18 + commands: + - composer validate + - composer install --prefer-dist - name: Test Friendica image: friendicaci/php7.3:php7.3.28 environment: @@ -79,8 +84,6 @@ steps: MEMCACHED_HOST: "memcached" MEMCACHE_HOST: "memcached" commands: - - composer validate - - composer install --prefer-dist - cp config/local-sample.config.php config/local.config.php - if ! bin/wait-for-connection $MYSQL_HOST $MYSQL_PORT 300; then echo "[ERROR] Waited 300 seconds, no response" >&2; exit 1; fi - mysql -h$MYSQL_HOST -P$MYSQL_PORT -p$MYSQL_PASSWORD -u$MYSQL_USER $MYSQL_DATABASE < database.sql @@ -108,6 +111,11 @@ type: docker name: php7.4-mariadb steps: + - name: Composer install + image: friendicaci/php7.4:php7.4.18 + commands: + - composer validate + - composer install --prefer-dist - name: Test Friendica image: friendicaci/php7.4:php7.4.18 environment: @@ -122,8 +130,6 @@ steps: XDEBUG_MODE: "coverage" commands: - phpenmod xdebug - - composer validate - - composer install --prefer-dist - cp config/local-sample.config.php config/local.config.php - if ! bin/wait-for-connection $MYSQL_HOST $MYSQL_PORT 300; then echo "[ERROR] Waited 300 seconds, no response" >&2; exit 1; fi - mysql -h$MYSQL_HOST -P$MYSQL_PORT -p$MYSQL_PASSWORD -u$MYSQL_USER $MYSQL_DATABASE < database.sql @@ -161,6 +167,11 @@ type: docker name: php8.0-mariadb steps: + - name: Composer install + image: friendicaci/php7.4:php7.4.18 + commands: + - composer validate + - composer install --prefer-dist - name: Test Friendica image: friendicaci/php8.0:php8.0.5 environment: @@ -173,8 +184,6 @@ steps: MEMCACHED_HOST: "memcached" MEMCACHE_HOST: "memcached" commands: - - composer validate - - composer install --prefer-dist - cp config/local-sample.config.php config/local.config.php - if ! bin/wait-for-connection $MYSQL_HOST $MYSQL_PORT 300; then echo "[ERROR] Waited 300 seconds, no response" >&2; exit 1; fi - mysql -h$MYSQL_HOST -P$MYSQL_PORT -p$MYSQL_PASSWORD -u$MYSQL_USER $MYSQL_DATABASE < database.sql From 0aa23b813ff7a1d411f7c67de8dfd1dc8eae8c71 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 25 May 2021 09:21:37 +0200 Subject: [PATCH 5/5] adjusted test case --- tests/legacy/ApiTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 4a1839f8c..423294e59 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -2309,13 +2309,13 @@ class ApiTest extends FixtureTest [ 'network' => 'feed', 'title' => 'item_title', - 'uri-id' => 1, + 'uri-id' => -1, 'body' => '', 'plink' => 'item_plink' ] ); - self::assertEquals("item_title\n\nParent status", $result['text']); - self::assertEquals('

item_title


Parent statusitem_plink', $result['html']); + self::assertEquals("item_title", $result['text']); + self::assertEquals('

item_title


item_plink', $result['html']); } /**