zendframework / zend-test

Test component from Zend Framework
BSD 3-Clause "New" or "Revised" License
18 stars 38 forks source link

Memory Leak in Application #69

Closed wodka closed 5 years ago

wodka commented 6 years ago

I just ran into an out of memory error and tried to figure out why it is happening. The moment the Application is used the memory goes up and never down.

Code to reproduce the issue

Depending on how much memory you want it to consume you can increase the array size of the data provider.

<?php

use Zend\Test\PHPUnit\Controller\AbstractControllerTestCase;

class UselessTest extends AbstractControllerTestCase
{
    public function setUp()
    {
        parent::setUp();

        $this->setApplicationConfig(
            [
                'modules'                 => [
                    'Zend\\Router',
                ],
                'module_listener_options' => [],
            ]
        );
    }

    /**
     * @dataProvider dataProvider
     */
    public function testNull($variable)
    {
        $this->getApplication();

        echo memory_get_usage(true) / 1000 / 1024 . PHP_EOL;

        $this->assertNull($variable);
    }

    public static function dataProvider()
    {
        return array_fill(0, 1000, [ null ]);
    }
}

Expected results

I would expect the memory to stay low - ie similar to not using the Application (~6Mb for all tests)

Actual results

Memory usage keeps growing

image

porebskk commented 5 years ago

Experiencing the same for larger apps with lots of integration tests (zf3 + doctrine2). The memory piles up for every single test that was executed. This affects all test that inherit from AbstractHttpControllerTestCase.

snapshotpl commented 5 years ago

Same issue. This is due to the global state in ZF3.

porebskk commented 5 years ago

@snapshotpl could you point me to where the global state is hold in zf3? Maybe it is possible to clear or reset the state in order to overcome this memory collection madness.

ezimuel commented 5 years ago

@porebskk, @snapshotpl, @wodka I'm looking into this issue.