Skip to content

PDO Too many connections when running test suite #18471

@ryrobbo

Description

@ryrobbo
  • Laravel Version: 5.4.16
  • PHP Version: 7.1
  • Database Driver & Version: MySQL

Description:

I have a test suite which now has 140 tests. Each of my tests uses the DatabaseMigrations trait along with a dedicated database solely for tests to run against.

When PHP Unit gets to the last test it fails with the following error:

Caused by
Doctrine\DBAL\Driver\PDOException: SQLSTATE[08004] [1040] Too many connections

I can run this test individually and it passes fine.

After finding this issue (#10619 (comment)) I tried the following but the problem still persists:

  • Added the PDO::ATTR_PERSISTENT => false option to my test database connection entry
  • Added the following code to the DatabaseMigrations trait:
$this->beforeApplicationDestroyed(function () {
    $this->artisan('migrate:rollback');

    foreach ($this->app->make('db')->getConnections() as $connection) {
        $connection->disconnect();
    }
});

Steps To Reproduce:

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions