Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doctrine issues after first request is made. #2042

Merged
merged 1 commit into from Jun 22, 2015

Conversation

AlexStansfield
Copy link
Contributor

Related to #2025

I found this change fixed all the problems I was having when using doctrine to create data in a transaction.

Unsure if it's the right solution, but means my tests now work.

@AlexStansfield
Copy link
Contributor Author

Any chance any one has had a chance to look at this? I don't know if it's the right solution, but it works for us. It would be great to get this bug fixed so we can reliably run our tests without needing to patch codeception.

@DavertMik
Copy link
Member

If it works for you and tests pass why not to merge then )

DavertMik added a commit that referenced this pull request Jun 22, 2015
Fix doctrine issues after first request is made.
@DavertMik DavertMik merged commit 6c1b47f into Codeception:2.0 Jun 22, 2015
@AlexStansfield
Copy link
Contributor Author

Haha ok, I don't claim to know anywhere near enough about the internals of the symfony kernel but if it doesn't break anyone else's tests then I'm happy 😀

@vyarmolenko
Copy link
Contributor

The solution to clone kernel between requests causes memory leak in functional tests. It can be seen on tests with multiple requests and/or multiple tests in a suite.

I had 'out of memory' errors when ran my test. I changed the code of Lib/Connector/Symfony2.php to its previous version and it works now.

In relation to [https://github.com//issues/2025]:
In it's current implementation when 'cleanup: true' codeception initializes Doctrine transaction after it creates Symfony2 web client. It may be the cause of problems with the first transaction related routines.
In my test I needed to run different requests against the same db so I implemented a helper method (mostly from codeception sources). It first rolls back codeception's transaction and initializes its own transaction which is being rolled back between requests:

   /*
     *  Rollback codeception's or any other external transaction(s) and set own  
     */
    public function prepareDatabase($isTransactional = true)
    {
        while ($this->em->getConnection()->isTransactionActive()) {
            try {
                $this->em->getConnection()->rollback();
            } catch (\PDOException $e) {
            }
        }
        $em = $this->em;
        $reflectedEm = new \ReflectionClass($em);
        if ($reflectedEm->hasProperty(' repositories')) {
            $property = $reflectedEm->getProperty('repositories');
            $property->setAccessible(true);
            $property->setValue($em, []);
        }
        $this->em->clear();
        if ($isTransactional) {
            $this->em->getConnection()->beginTransaction();
        }
    }

@AlexStansfield
Copy link
Contributor Author

Would changing

$this->kernel = clone $this->kernel;

to

$tmpKernel = $this->kernel;
$this->kernel = clone $tmpKernel;
unset($tmpKernel);

have enabled php to garbage collect when it needs the memory?

I will revert the change here to see if our tests run successful (and this was fixed else where) or if the initial problem reappears.

@AlexStansfield
Copy link
Contributor Author

Just reread you comment, and will look into what you think might be causing the transaction issue

@raistlin
Copy link
Member

raistlin commented Apr 4, 2016

@vyarmolenko Could you prepare a pull request with your proposed solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants