Unverified Commit 14c2c9f0 authored by Oliver Klee's avatar Oliver Klee
Browse files

[WIP] Test the testing framework speed patch

parent c7fa1fdd
commit 77980214fc32faf374129f1edf90cb711803944b
Author: Oliver Klee <typo3-coding@oliverklee.de>
Date: Thu Aug 19 22:26:24 2021 +0200
[TASK] Only truncate tables that have been touched
"Touched" means "the auto increment has been changed (if there is
one)" or "there are some records in it".
This massively speeds up functional tests (as the table truncation
is the slowest part of the test setup).
diff --git a/src/TestingFramework/TestSystem/AbstractTestSystem.php b/src/TestingFramework/TestSystem/AbstractTestSystem.php
index 468ba3b..87cd256 100644
--- a/src/TestingFramework/TestSystem/AbstractTestSystem.php
+++ b/src/TestingFramework/TestSystem/AbstractTestSystem.php
@@ -19,6 +19,7 @@ use Nimut\TestingFramework\Exception\Exception;
use Nimut\TestingFramework\File\NtfStreamWrapper;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
+use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -224,11 +225,19 @@ abstract class AbstractTestSystem
*/
protected function initializeTestDatabase()
{
+ /** @var Connection $connection */
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
- $schemaManager = $connection->getSchemaManager();
- foreach ($schemaManager->listTables() as $table) {
- $connection->truncate($table->getName());
+
+ $databaseName = $connection->getDatabase();
+ $query = "SHOW TABLE STATUS FROM $databaseName";
+ $result = $connection->executeQuery($query)->fetchAll();
+ foreach ($result as $tableData) {
+ $isChanged = ((int) $tableData['Auto_increment']) > 1 || ((int) $tableData['Rows']) > 0;
+ if ($isChanged) {
+ $tableName = $tableData['Name'];
+ $connection->truncate($tableName);
+ }
}
}
......@@ -36,6 +36,7 @@
},
"require-dev": {
"codeception/codeception": "^4.1.5",
"cweagans/composer-patches": "^1.7",
"helhum/typo3-composer-setup": "^0.5.7",
"nimut/testing-framework": "^5.0.3",
"phpunit/phpunit": "^7.5.20",
......@@ -53,6 +54,12 @@
"branch-alias": {
"dev-main": "2.0.x-dev"
},
"composer-exit-on-patch-failure": true,
"patches": {
"nimut/testing-framework": {
"Only truncate changed tables": "build/patches/testing-framework/faster-truncate.diff"
}
},
"typo3/cms": {
"extension-key": "tea",
"web-dir": ".Build/public"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment