Comments (15)
@rvadym Do you have any code to close and reopen connection that you can share? Is it something that may be automated?
from liipfunctionaltestbundle.
I have also encountered this error. For me it happens each time a test loads a different set of fixtures.
Narrowing it down, the loadFixtures
method switches the database, but I'm guessing, the connection has stored procedures for that database. The only solution I could come up with is to close the connection before the fixtures are loaded.
from liipfunctionaltestbundle.
Ok. I'm still not sure what exactly is causing this issue, but I managed to get around it (not even going to say "solve it"). We didn't get this error at the beginning but only started seeing it lately. We are still in active development phase with the project, so our schema is growing at a steady pace. So I started thinking it's somehow related to the schema size. After researching the error message I started thinking it might have something to do with how SQLite writes the changes to the file or how the schema update transactions are committed etc. and somehow all the updates not beeing written/committed yet when the first query starts preparing. So I just put a sleep(2); between the loadFixtures call and the first query. And what do you know, the error disappeared.
Ok, so putting a sleep() call after all the loadFixtures calls is not acceptable, but luckily it only has to be after the first one. But how do we know what's the first one? If we add new tests we might have to move the sleep call around. I solved it (at least for now) by creating a new test class that has a name that will always be the first test executed. Inside that test there is one loadFixtures call and after that a sleep(1) call and nothing else. This ensures that the schema gets created at the beginning and it has time to finnish writing before the actual queries start. Not exactly an ideal solution, but it makes our build pass so I'm ok with that.
So I guess it's a little bit lower level issue than this bundle, still not sure if the issue is with SQLite itself or how PHP/PDO uses it, but it's good to know how to get around it in case anyone else runs into the same error using this bundle.
from liipfunctionaltestbundle.
Understanding how unit tests work and deal with DB integrations, a TRUNCATE table is issued before the test starts and loads up the initial dataset, to ensure it's also initial and known at the start of the test.
I remember that I once had this issue (and didn't blog about it) where my DB contained a different schema than the one that was loaded at first execution of the unit test. Check both your test DB and the initial dataset structure to see if you have any differences between them.
I know integration tests can be a pain, because you have to deal with more than just your code. Start looking in this direction. My gut tells me it's something related to the initial loading of the dataset and differences between the structure of the database schemas.
from liipfunctionaltestbundle.
In my case, it was cache issue. I had job below in my build.xml
which caused the problem.
<target name="prepare">
<exec executable="app/console">
<arg value="cache:clear"/>
<arg value="--env=test"/>
</exec>
</target>
OR
I was using https://github.com/liip/LiipFunctionalTestBundle for loading fixtures so setting liip_functional_test: cache_sqlite_db
to false
solved problem.
from liipfunctionaltestbundle.
@cvuorinen can you reproduce this bug with the current version? Can we close this issue? Thanks.
from liipfunctionaltestbundle.
Haven't seen that error for a long time and we are no longer using the sleep(1) call so you can close it. Not really sure what caused it in the first place, but has not been an issue for us lately.
from liipfunctionaltestbundle.
I ran into this issue just now. It only occurs if I run our entire 500+ test / 5000+ assertion test suite and only for a single test case where we use client
to test requests to our API. The difference of this testcase to other similar cases is that I am calling loadFixtures()
with an empty array instead of with a fixtures class like in all the other working API tests.
What is also strange is that if I run only the tests of the test class containing this failing test, the test doesn't fail (the failing test is the last of about 20 tests in this class). Neither does it fail if I run tests for the entire bundle. It only fails when I run the entire test suite (takes about 30 minutes).
Adding sleep(1);
to immediately after loadFixtures([]);
doesn't fix the failing test.
from liipfunctionaltestbundle.
After some more testing it turned out that the root issue was that there was a loadFixtures([FixturesClass])
in the setUp()
method and then inside the test the first call was to loadFixtures([])
which apparently was too quick of a change for SQlite to catch up. Putting a sleep
between those two calls probably would have helped but I simply fixed the issue now by getting rid of the loadFixtures()
call in setUp()
and having each test load the required fixtures individually.
from liipfunctionaltestbundle.
@advancingu I had the same error recently when using a repository to fetch some data or calling loadFixtures()
2 times in the same test (I don't remember exactly), I'll try to provide a failing example.
from liipfunctionaltestbundle.
Here is a PR with a failing test while it looks normal: alexislefebvre#24
Maybe this code was not a good idea though:
$this->client = static::makeClient();
$em = $this->client->getContainer()
->get('doctrine.orm.entity_manager');
from liipfunctionaltestbundle.
It is required to close and reopen connection if you change SQLite database file or database schema somehow.
from liipfunctionaltestbundle.
@alexislefebvre Sorry, just found your question. Hope it will help somebody else.
Close:
$connection = $this->getContainer()->get('doctrine.orm.entity_manager')->getConnection();
if (null !== $connection) {
$connection->close();
}
And Symfony will open connection automatically after you close it I guess.
from liipfunctionaltestbundle.
I solved this error by applying this configuration :
cache_sqlite_db: true
Hope it will help some of you !
from liipfunctionaltestbundle.
from liipfunctionaltestbundle.
Related Issues (20)
- Question: 3.4.0 Release HOT 4
- Call to undefined method doRun() HOT 6
- Allow purging sqlite db with out dropping the existing db HOT 2
- Restore β--prefer-lowestβ job on Travis CI
- Symfony 5 error during installation
- Support PHP8
- Error with definition of method getContainer and Symfony 5.3 HOT 4
- WebTestCase and FixturesTrait define the same property ($containers) HOT 4
- Call to deprecated method isMasterRequest() when isMainRequest() returns false HOT 2
- Regression in getContainer with symfony 5.3
- 4.5 WebTestCase $environment BC break
- Can't overwrite WebTestCase $env static property
- Symfony 6 compatibility HOT 2
- Use issue form
- Restore test with max_query_count: 1
- Dependencies upgrade: doctrine/annotations HOT 4
- [RFC] Drop support of PHP 7.2 and 7.3? HOT 1
- Symfony 7 compatibility HOT 14
- Remove fixtures and doctrine/* from composer.json? HOT 1
- Add notes in documentation to mention loginUser() and other methods from Symfony
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liipfunctionaltestbundle.