Skip to content

Commit

Permalink
Improve memory leak testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jun 22, 2021
1 parent ad5c0bb commit 00a3ce5
Show file tree
Hide file tree
Showing 25 changed files with 47 additions and 46 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
services:
mysql:
image: mysql:8
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=atk4_pass -e MYSQL_USER=atk4_test -e MYSQL_PASSWORD=atk4_pass -e MYSQL_DATABASE=atk4_test__data --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=atk4_pass_root -e MYSQL_USER=atk4_test -e MYSQL_PASSWORD=atk4_pass -e MYSQL_DATABASE=atk4_test__data --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
mssql:
image: mcr.microsoft.com/mssql/server
env:
Expand Down Expand Up @@ -138,11 +138,12 @@ jobs:
if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/phpstan 'behat/*' --dev ; fi
composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader
if [ "${{ matrix.type }}" == "Phpunit Lowest" ]; then composer update --ansi --prefer-dist --prefer-lowest --prefer-stable --no-interaction --no-progress --optimize-autoloader ; fi
if [ "${{ matrix.type }}" == "Phpunit Burn" ]; then sed -i 's/ *public function runBare(): void/public function runBare(): void { gc_collect_cycles(); $mem0 = memory_get_usage(); for ($i = 0; $i < '"$(if [ \"$GITHUB_EVENT_NAME\" == \"schedule\" ]; then echo 5; else echo 5; fi)"'; ++$i) { $this->_runBare(); if ($i === 0) { gc_collect_cycles(); $mem1 = memory_get_usage(); } } gc_collect_cycles(); $mem2 = memory_get_usage(); if ($mem2 - 3072 * 1024 > $mem0 || $mem2 - 1536 * 1024 > $mem1) { $this->onNotSuccessfulTest(new AssertionFailedError("Memory leak detected! (" . round($mem0 \/ (1024 * 1024), 3) . " + " . round(($mem1 - $mem0) \/ (1024 * 1024), 3) . " + " . round(($mem2 - $mem1) \/ (1024 * 1024), 3) . " MB, " . $i . " iterations)")); } } private function _runBare(): void/' vendor/phpunit/phpunit/src/Framework/TestCase.php && cat vendor/phpunit/phpunit/src/Framework/TestCase.php | grep '_runBare(' ; fi
if [ "${{ matrix.type }}" == "Phpunit Burn" ]; then sed -i 's/ *public function runBare(): void/public function runBare(): void { gc_collect_cycles(); gc_collect_cycles(); $mem0 = memory_get_usage(); for ($i = 0; $i < '"$(if [ \"$GITHUB_EVENT_NAME\" == \"schedule\" ]; then echo 20; else echo 20; fi)"'; ++$i) { $this->_runBare(); gc_collect_cycles(); gc_collect_cycles(); if ($i === 0) { $mem1 = memory_get_usage(); } } $mem2 = memory_get_usage(); if ($mem2 - 3072 * 1024 > $mem0 || $mem2 - 1024 * 1024 > $mem1) { $this->onNotSuccessfulTest(new AssertionFailedError("Memory leak detected! (" . round($mem0 \/ (1024 * 1024), 3) . " MB + " . round(($mem1 - $mem0) \/ (1024 * 1024), 3) . " MB + " . round(($mem2 - $mem1) \/ 1024, 3) . " KB, " . $i . " iterations)")); } } private function _runBare(): void/' vendor/phpunit/phpunit/src/Framework/TestCase.php && cat vendor/phpunit/phpunit/src/Framework/TestCase.php | grep '_runBare(' ; fi
- name: Init
run: |
mkdir -p build/logs
php -r '(new PDO("mysql:host=mysql", "root", "atk4_pass_root"))->exec("ALTER USER '"'"'atk4_test'"'"'@'"'"'%'"'"' WITH MAX_USER_CONNECTIONS 5");'
php demos/_demo-data/create-sqlite-db.php
- name: "Run tests: SQLite (only for Phpunit)"
Expand Down
2 changes: 1 addition & 1 deletion phpunit-mssql.xml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\AtkPhpunit\ResultPrinter" colors="true">
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\Phpunit\ResultPrinter" colors="true">
<php>
<var name="DB_DSN" value="sqlsrv:Server=mssql;Database=master" />
<var name="DB_USER" value="sa" />
Expand Down
2 changes: 1 addition & 1 deletion phpunit-mysql.xml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\AtkPhpunit\ResultPrinter" colors="true">
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\Phpunit\ResultPrinter" colors="true">
<php>
<var name="DB_DSN" value="mysql:dbname=atk4_test__data;host=mysql" />
<var name="DB_USER" value="atk4_test" />
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\AtkPhpunit\ResultPrinter" colors="true">
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\Phpunit\ResultPrinter" colors="true">
<php>
<var name="DB_DSN" value="sqlite::memory:" />
<var name="DB_USER" value="" />
Expand Down
4 changes: 2 additions & 2 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\App;
use Atk4\Ui\HtmlTemplate;

class AppTest extends AtkPhpunit\TestCase
class AppTest extends TestCase
{
protected function getApp()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\Button;

class ButtonTest extends AtkPhpunit\TestCase
class ButtonTest extends TestCase
{
/**
* @doesNotPerformAssertions
Expand Down
4 changes: 2 additions & 2 deletions tests/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;

class AppMock extends \Atk4\Ui\App
{
Expand All @@ -24,7 +24,7 @@ protected function outputResponse(string $data, array $headers): void
}
}

class CallbackTest extends AtkPhpunit\TestCase
class CallbackTest extends TestCase
{
/** @var string */
private $htmlDoctypeRegex = '~^<!DOCTYPE~';
Expand Down
4 changes: 2 additions & 2 deletions tests/DemosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Data\Persistence;
use Atk4\Ui\App;
use GuzzleHttp\Client;
Expand All @@ -17,7 +17,7 @@
*
* Requests are emulated in the same process. It is fast, but some output or shutdown functionality can not be fully tested.
*/
class DemosTest extends AtkPhpunit\TestCase
class DemosTest extends TestCase
{
/** @const string */
protected const ROOT_DIR = __DIR__ . '/..';
Expand Down
4 changes: 2 additions & 2 deletions tests/ExecutorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Data\Model;
use Atk4\Data\Persistence\Array_;
use Atk4\Ui\App;
Expand Down Expand Up @@ -36,7 +36,7 @@ protected function init(): void
}
}

class ExecutorFactoryTest extends AtkPhpunit\TestCase
class ExecutorFactoryTest extends TestCase
{
/** @var Model */
public $model;
Expand Down
4 changes: 2 additions & 2 deletions tests/ForFieldUiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Data\Model;
use Atk4\Data\Persistence;

Expand All @@ -24,7 +24,7 @@ protected function init(): void
* Test is designed to verify that field which is explicitly editable should appear and be editable
* even if 'never_persist' is set to true.
*/
class ForFieldUiTest extends AtkPhpunit\TestCase
class ForFieldUiTest extends TestCase
{
/** @var Model */
public $m;
Expand Down
4 changes: 2 additions & 2 deletions tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Data\Model;
use Atk4\Ui\App;
use Atk4\Ui\Form;

class FormTest extends AtkPhpunit\TestCase
class FormTest extends TestCase
{
/** @var Form */
public $f;
Expand Down
2 changes: 1 addition & 1 deletion tests/GridTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Atk4\Ui\Table;

class GridTest extends \Atk4\Core\AtkPhpunit\TestCase
class GridTest extends \Atk4\Core\Phpunit\TestCase
{
use Concerns\HandlesTable;

Expand Down
4 changes: 2 additions & 2 deletions tests/HtmlTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\Exception;
use Atk4\Ui\HtmlTemplate;
use Atk4\Ui\HtmlTemplate\TagTree;

class HtmlTemplateTest extends AtkPhpunit\TestCase
class HtmlTemplateTest extends TestCase
{
protected function assertSameTemplate(string $expectedTemplateStr, HtmlTemplate $template): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/JsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\Button;
use Atk4\Ui\View;

class JsIntegrationTest extends AtkPhpunit\TestCase
class JsIntegrationTest extends TestCase
{
public function testIdIntegrity1(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/JsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\Jquery;
use Atk4\Ui\JsChain;
use Atk4\Ui\JsExpression;
use Atk4\Ui\JsFunction;

class JsTest extends AtkPhpunit\TestCase
class JsTest extends TestCase
{
public function testBasicExpressions(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ListerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\Exception;
use Atk4\Ui\HtmlTemplate;

class ListerTest extends AtkPhpunit\TestCase
class ListerTest extends TestCase
{
/**
* @doesNotPerformAssertions
Expand Down
4 changes: 2 additions & 2 deletions tests/LocaleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\Exception;
use Atk4\Ui\Locale;

class LocaleTest extends AtkPhpunit\TestCase
class LocaleTest extends TestCase
{
public function testException(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;

class PaginatorTest extends AtkPhpunit\TestCase
class PaginatorTest extends TestCase
{
public $p;

Expand Down
4 changes: 2 additions & 2 deletions tests/PostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Data\Model;

class PostTest extends AtkPhpunit\TestCase
class PostTest extends TestCase
{
/** @var Model */
public $model;
Expand Down
4 changes: 2 additions & 2 deletions tests/RenderTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\View;

/**
* Multiple tests to ensure that adding views through various patterns initializes them
* nicely still.
*/
class RenderTreeTest extends AtkPhpunit\TestCase
class RenderTreeTest extends TestCase
{
public function testBasic(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/TableColumnColorRatingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\Table;

class TableColumnColorRatingTest extends AtkPhpunit\TestCase
class TableColumnColorRatingTest extends TestCase
{
use Concerns\HandlesTable;

Expand Down
4 changes: 2 additions & 2 deletions tests/TableColumnLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\Table;

class TableColumnLinkTest extends AtkPhpunit\TestCase
class TableColumnLinkTest extends TestCase
{
use Concerns\HandlesTable;

Expand Down
4 changes: 2 additions & 2 deletions tests/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;

class TableTest extends AtkPhpunit\TestCase
class TableTest extends TestCase
{
/**
* @doesNotPerformAssertions
Expand Down
4 changes: 2 additions & 2 deletions tests/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;

class TagTest extends AtkPhpunit\TestCase
class TagTest extends TestCase
{
public function getApp()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Atk4\Ui\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Exception;
use Atk4\Core\Phpunit\TestCase;

class ViewTest extends AtkPhpunit\TestCase
class ViewTest extends TestCase
{
/**
* Test redering multiple times.
Expand Down

0 comments on commit 00a3ce5

Please sign in to comment.