GithubHelp home page GithubHelp logo

Comments (15)

alexislefebvre avatar alexislefebvre commented on July 17, 2024 2

@rvadym Do you have any code to close and reopen connection that you can share? Is it something that may be automated?

from liipfunctionaltestbundle.

twifty avatar twifty commented on July 17, 2024 1

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.

cvuorinen avatar cvuorinen commented on July 17, 2024

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.

DragonBe avatar DragonBe commented on July 17, 2024

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.

bentcoder avatar bentcoder commented on July 17, 2024

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.

alexislefebvre avatar alexislefebvre commented on July 17, 2024

@cvuorinen can you reproduce this bug with the current version? Can we close this issue? Thanks.

from liipfunctionaltestbundle.

cvuorinen avatar cvuorinen commented on July 17, 2024

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.

advancingu avatar advancingu commented on July 17, 2024

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.

advancingu avatar advancingu commented on July 17, 2024

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.

alexislefebvre avatar alexislefebvre commented on July 17, 2024

@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.

alexislefebvre avatar alexislefebvre commented on July 17, 2024

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.

rvadym avatar rvadym commented on July 17, 2024

It is required to close and reopen connection if you change SQLite database file or database schema somehow.

from liipfunctionaltestbundle.

rvadym avatar rvadym commented on July 17, 2024

@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.

lpitteloud avatar lpitteloud commented on July 17, 2024

I solved this error by applying this configuration :

cache_sqlite_db: true

Hope it will help some of you !

from liipfunctionaltestbundle.

lsmith77 avatar lsmith77 commented on July 17, 2024

#318

from liipfunctionaltestbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.