Description
- Laravel Version: v6.6.0
- PHP Version: 7.4.0 and 7.3
- Database Driver & Version: sqlite 3.24.0 and MySQL 5.7.25
Description:
Recently we noticed our testsuite throwing out of memory errors, a problem that hadn't happened before. Doing a little debugging we found that each test adds around 2 MB of memory usage. Our test suite has around 1000 tests, and to have it fully run we need around 600 MB of memory allocated.
Around 80% of our test cases are "unit" tests, though they do interact with the database, 20% are integration tests that will simulate requests to controllers, using the built-in Laravel functionality.
We're using both the CreatesApplication
and RefreshDatabase
traits as provided by Laravel, and use an in-memory sqlite database, however for this issue I also ran our test suite on a MySQL database, where the same leak seems to happen.
I have looked at several older issues and stackoverflow questions, though none of them seem to provide a solution that works in this case.
Steps To Reproduce:
Add this teardown function in the base testcase, and observe.
protected function tearDown(): void
{
parent::tearDown();
echo memory_get_usage() . PHP_EOL;
}
Output:
.57536280
.59370792
.63121592
.65270952
…
.83115760
.84632896
.85978784
.82666928
…