-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Too many connections error during testing with 2 databases #23513
Comments
Ok before digging deeper into this, can you try and remove the () after $this->connectionsToTransact and see if this still happens? |
@tomhatzer I've tried with I've also tried hard-coding them like:
or like
or like
or like
among others. |
@denitsa-cm Ok good... Next question: When do you create the new database connections? Do you create them in a wrapper class that executes all your tests or do you create a new connection within every single test class? |
I manually
I would assume the connections are open in |
@tomhatzer It is also worth noting that during tests I have calls to factories that look like this:
Note that a Vendor in this case is on a P.S. Just tried replacing all calls from a |
@denitsa-cm Ok I see... Can you try this class as your base class?
This should rollback all changes and disconnect everything afterwards. Do you get any log output from Laravel during the tests? Any errors or anything like that? The basic problem is, as in the other issues belonging to database connections, that the connections don't get closed.
|
@tomhatzer Just tried it and ran Class looks like this:
This has really been bothering me for a while :) |
@denitsa-cm do you possibly have a public repository with a little test implementation and example code? I don't think we'll get any further here with the current way. |
@tomhatzer I have temporarily increased the database connections limit to be able to run the tests. I will try to reproduce it in a clean repository soon. The things is the error only happens with many tests and multiple database connections so I'll need some time to set it up. Will post here when I've done that! :) Thank you for your help! |
If you can reproduce in an clean repo - please let us know |
This is still broken. In unittest teardown function, do Ideally Application->flush() should also force close all connections, so if there are any memory leaks that keep references to connection object, the actual db connection gets closed off. Or better yet, fix circular references/memory leaks so that connection objects are released. Testing for memory leaks proof with xdebug extension should be easy: $connection = DB::connection(); if Application->flush() released everything properly and closed connections, xdebug should show that 'pdo' and 'connection' variables are objects, which have only 1 reference (local variables in function). If the number of references is 2 or more, then there is a memory/connection leak which makes tests unrunnable for big projects. |
This was one of the only github issues I've found referencing this issue, so in case this helps anyone else here's what we're doing. We assumed Laravel's teardown functionality would close these connections but monitoring our mysql container during a fairly large testsuite, at a certain point we get all failures and a blast of Also ran Note: We're using https://tenancyforlaravel.com/
Hope this helps! |
Description:
I am getting a
Too many connections
error during phpunit testing with a test suite of about 150 tests, starting after approximately half of the test have run.Error stack:
Steps To Reproduce:
I have 2 mysql connections, lots of tests making calls to model factories, and the following in a base test class extending from
Illuminate\Foundation\Testing\TestCase
:The text was updated successfully, but these errors were encountered: