-
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
Some traits of database tests do not close the connection even after the test is finished #49311
Comments
Related to #18056. Either
|
You may try to use add the following code in protected function setUp(): void
{
$this->beforeApplicationDestroyed(function () {
foreach (array_keys($this->app['db']->getConnections()) as $name) {
$this->app['db']->purge($name);
}
});
parent::setUp();
} We have this in Framework's |
@crynobone I've already tried and I confirmed it solves this problem, but I believe that it should be implemented on framework core. |
|
At least we should update the trait doc comments and Laravel official documentation... |
@taylorotwell Hi, how do you think about this? |
We'd appreciate a PR here, thanks. |
@driesvints Please re-open this, there's still a problem |
First of all, I would like to apologize for breaking the real world application. However, I think this issue should be fixed. In tearDown:
The above process is being performed. I find it strange that the database connection is left open (and/or leaked). Is there some reason? |
@taylorotwell @driesvints @KentarouTakeda @rikvdh @crynobone I opened the discussion, please check it out: |
Laravel Version
10.35.0
PHP Version
8.3.0
Database Driver & Version
PostgreSQL 16.1 for MacOS(MacPorts) / Probably all databases
Description
DatabaseMigrations
andDatabaseTruncation
do not close the database connection at the end of each test. Therefore, the database connection remains open for the number of tests.As a result, when running a large number of tests, we may encounter a maximum number of connections error or a lack of resources on the database side.
DatabaseTransactions
andRefreshDatabase
do not have this problem.Steps To Reproduce
In the following example, I adjusted the PostgreSQL config to make it easier to see what happens. It probably happens with other databases as well.
Start the server with postgresql.conf set as follows.
Run the following test:
The test will fail with the following error for example:
The following is recorded in the database server log:
DatabaseTransactions
andRefreshDatabase
, the connection is closed after each test as per their implementation, so no error occurs and the log is recorded as follows.The text was updated successfully, but these errors were encountered: