Project

General

Profile

Actions

Task #60280

closed

Suffix for functional test database

Added by Tomas Norre Mikkelsen over 10 years ago. Updated over 7 years ago.

Status:
Rejected
Priority:
Could have
Assignee:
-
Category:
Tests
Target version:
-
Start date:
2014-07-11
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
hard
Sprint Focus:
Remote Sprint

Description

Hi,

I would like to discuss/suggest the possibility to have a surfix as test-database name in the functional testing.
Right now the name is the original database name surfixed with _ft + sha1(testClassName)

I would like to be able to set my own surfix like _test like in the "old" days where was using the same database for every test. I know you most likely have your arguments for changing this, but i she this as a disadvantage in automate setup/enviroments.

Lets say.

I Create a new database_ft12jd3jak for test A,
I Create a new database_ftdsf221qk for test B etc.

I the test end up dying in some of the process before we reach the cleanup then we can end up floating the database server with incomplete database.

I don't like the idea that i need to grant my database-user to be allowed to create multiple database with naming convention database_ft*

I don't know yet how this should be implemented in best practice, but i would like to have some feedback on this topic.

I'm more than happy to help implement a good solutions so this "issue" can be solved.

Any feedback is appreciated.

Actions #1

Updated by Anja Leichsenring almost 10 years ago

  • Sprint Focus set to On Location Sprint
Actions #2

Updated by Tymoteusz Motylewski almost 10 years ago

1. I agree that we should think about improving the db cleanup. I also run into situations where functional tests suite leaves many db after execution.
2. The sha1 suffix for the db names is needed, as usually we're running the functional tests in parallel, see travis.yml

find . -wholename '*typo3/sysext/*/Tests/Functional/*Test.php' | parallel --gnu 'echo; echo "Running functional test suite {}"; ./bin/phpunit --colors -c typo3/sysext/core/Build/FunctionalTests.xml {}'

maybe we can pass some flag as a param/env to switch on/off this prefix?

Actions #3

Updated by Anja Leichsenring almost 10 years ago

  • Subject changed from Surfix for functional test database to Suffix for functional test database
Actions #4

Updated by Steffen Müller almost 10 years ago

We solve these concerns by not mixing test and production DBs.

The tests are run in an isolated test environment: separated MySQL process on a dedicated TCP port/ socket, which sole purpose is to serve tests.

for example:

mysqld_safe --port=3307 --socket="/var/run/mysqld/mysqld-testing.sock" --user mysql --pid-file="/var/run/mysqld/mysqld-testing.pid" --datadir="/mnt/testramdisk/mysql" --skip-grant-tables

Actions #5

Updated by Benni Mack over 9 years ago

  • Target version set to 7.4 (Backend)
Actions #6

Updated by Susanne Moog over 9 years ago

  • Target version changed from 7.4 (Backend) to 7.5
Actions #7

Updated by Anja Leichsenring over 9 years ago

  • Sprint Focus changed from On Location Sprint to Remote Sprint
Actions #8

Updated by Oliver Hader about 9 years ago

  • Status changed from New to Accepted
  • Target version changed from 7.5 to 7 LTS
  • Complexity set to hard
Actions #9

Updated by Mathias Schreiber about 9 years ago

  • Tracker changed from Bug to Task
  • Target version deleted (7 LTS)
Actions #10

Updated by Gerrit Code Review almost 9 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/46218

Actions #11

Updated by Gerrit Code Review almost 9 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/46218

Actions #12

Updated by Christian Kuhn almost 9 years ago

hey.

Ok, some background explanation:

First in "the old days" the unit tests had database requirements and always worked on the database configured in LocalConfiguration. This was fixed, unit tests don't need DB at all anymore. At this point functional tests didn't exist at all. So, this situation can not be compared to "old days".

The functionals need a DB. the name, username and password SHOULD be set via environment variables and fetching them from LocalConfiguration is only a fallback for lazy people. In general functionals should not be executed in an environment that has a "real" system in parallel.

Why multiple DB's are needed: Every test case (=test file) can define an own set of loaded extensions which define a set of tables + fields per test case. The system is created in a way that single tests of a test case must use the same db layout. Therefore one test case has one set of table+field definitions, a second test case probably has different db layout since a different set of extensions is loaded. If you then want to support to run multiple test cases in parallel (like the travis travis-ci does, have a look at .travis.yml in core root), you need different DB's for each test case. Parallelizing the tests has a huge positive performance impact.

Basically, the system creates the unique db per test file, populates the schema, then inserts whatever rows should be inserted, then runs the first test, then truncates this DB, then inserts rows of the next test, runs it, truncates, .... The difference between recreating a DB for each and every test and just truncating it between single tests is done since table creation is a pretty slow thing in mysql/maria and truncating is very fast. Not re-creating a DB for every single test thus speeds up the whole test suite enormously, even if mysql is running in a ramdisk. We're talking about factor 10 or something at the moment. This is significant since it is a difference between 10 minutes to an hour or something.

The problem with this setup is: phpunit is constructed in a way that single tests can not share information very well. So, the system does not know if a former test just created the DB already. It is not easy for a single test to find out whether it should create a fresh DB or if it should just truncate. Problem is here that in between multiple runs the schema may change and then you want your DB to be re-created, while in between single tests, the same DB should be re-used. Thus, instead we just store the date when a DB was created in a file per test case. A test reads this file and if the DB is older than some minutes, it will drop DB and create new, if it is "young" it will truncate and reuse. Goal: If you're in the process of hacking up a test and changing it, you're likely to have a fresh DB created each time, while multiple tests after each other truncate instead. BTW: You can force to re-create a DB in between runs, if the functional_* directories from typo3temp/ are deleted, this is where the single functional test instances are set up.

Another problem with phpunit is that a single test does not know if it is "the last one" of a test case: This is the main reason why there is no cleanup of DB's after finishing a test run. The only way to do this sort of clean ups is "tearDownAfterClass" (if i remember correctly), but unfortunately this method is a) static which gives us huge problems with information sharing to the helper class, it b) it does not help with the "process encapsulating" - every single tests runs in a single php process forked by phpunit. This forking is done to encapsulate single tests on PHP level from each other, if that is not enabled the system would for instance throw errors on defined constants. So, giving information from one single test run to another one is nearly impossible because of this process isolation. That's the reason why the database creation date is written to a file ...

I hope this explanation makes it a bit more clear why a) there is a single DB for each test case and b) why DB's are not deleted at the end. If you find a better solution to resolve all the above without speed loss, I'd be very interested.

All in all we currently need all these DB's. For the "suffix" thing: If you really insist on having the "_ft" configurable, the patch should imho be changed that a) no additional LocalConfiguration parameter is introduced, but maybe - if really needed - an additional environment variable is introduced to set this prefix.

Actions #13

Updated by Tomas Norre Mikkelsen almost 9 years ago

Hi Christian,

Thanks for the elaboration, I mostly agree with you.

The important part in my suggestion is not that I want to override the normal behavior, "just" want to extend the possibility to suffix databases and not use the _ft $this->identifier.

I know this comes with a performance price when running the testing, but for us it a matter of use these settings to limit the amount of DB's that has to be created to run a functional test for a given extension. We are not running the TYPO3 Core functional testing, we trust the active contributors to make sure that these are maintained and kept working.

Main take away from my suggestion, it's an option not a requirement to use the suffix.

About getting the settings from CLI arguments and not from LocalConfiguration.php is totally valid to me, and I can change that.

Actions #14

Updated by Christian Kuhn over 7 years ago

  • Status changed from Under Review to Rejected
Actions

Also available in: Atom PDF