Skip to content

Commit a87c419

Browse files
authored
Improve memory leak testing (#1642)
1 parent ad5c0bb commit a87c419

25 files changed

+47
-46
lines changed

.github/workflows/test-unit.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ jobs:
102102
services:
103103
mysql:
104104
image: mysql:8
105-
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"
105+
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"
106106
mssql:
107107
image: mcr.microsoft.com/mssql/server
108108
env:
@@ -138,11 +138,12 @@ jobs:
138138
if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/phpstan 'behat/*' --dev ; fi
139139
composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader
140140
if [ "${{ matrix.type }}" == "Phpunit Lowest" ]; then composer update --ansi --prefer-dist --prefer-lowest --prefer-stable --no-interaction --no-progress --optimize-autoloader ; fi
141-
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
141+
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 5; 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 - 1536 * 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
142142
143143
- name: Init
144144
run: |
145145
mkdir -p build/logs
146+
php -r '(new PDO("mysql:host=mysql", "root", "atk4_pass_root"))->exec("ALTER USER '"'"'atk4_test'"'"'@'"'"'%'"'"' WITH MAX_USER_CONNECTIONS 5");'
146147
php demos/_demo-data/create-sqlite-db.php
147148
148149
- name: "Run tests: SQLite (only for Phpunit)"

phpunit-mssql.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\AtkPhpunit\ResultPrinter" colors="true">
1+
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\Phpunit\ResultPrinter" colors="true">
22
<php>
33
<var name="DB_DSN" value="sqlsrv:Server=mssql;Database=master" />
44
<var name="DB_USER" value="sa" />

phpunit-mysql.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\AtkPhpunit\ResultPrinter" colors="true">
1+
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\Phpunit\ResultPrinter" colors="true">
22
<php>
33
<var name="DB_DSN" value="mysql:dbname=atk4_test__data;host=mysql" />
44
<var name="DB_USER" value="atk4_test" />

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\AtkPhpunit\ResultPrinter" colors="true">
1+
<phpunit bootstrap="vendor/autoload.php" printerClass="Atk4\Core\Phpunit\ResultPrinter" colors="true">
22
<php>
33
<var name="DB_DSN" value="sqlite::memory:" />
44
<var name="DB_USER" value="" />

tests/AppTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\App;
99
use Atk4\Ui\HtmlTemplate;
1010

11-
class AppTest extends AtkPhpunit\TestCase
11+
class AppTest extends TestCase
1212
{
1313
protected function getApp()
1414
{

tests/ButtonTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\Button;
99

10-
class ButtonTest extends AtkPhpunit\TestCase
10+
class ButtonTest extends TestCase
1111
{
1212
/**
1313
* @doesNotPerformAssertions

tests/CallbackTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88

99
class AppMock extends \Atk4\Ui\App
1010
{
@@ -24,7 +24,7 @@ protected function outputResponse(string $data, array $headers): void
2424
}
2525
}
2626

27-
class CallbackTest extends AtkPhpunit\TestCase
27+
class CallbackTest extends TestCase
2828
{
2929
/** @var string */
3030
private $htmlDoctypeRegex = '~^<!DOCTYPE~';

tests/DemosTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Data\Persistence;
99
use Atk4\Ui\App;
1010
use GuzzleHttp\Client;
@@ -17,7 +17,7 @@
1717
*
1818
* Requests are emulated in the same process. It is fast, but some output or shutdown functionality can not be fully tested.
1919
*/
20-
class DemosTest extends AtkPhpunit\TestCase
20+
class DemosTest extends TestCase
2121
{
2222
/** @const string */
2323
protected const ROOT_DIR = __DIR__ . '/..';

tests/ExecutorFactoryTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Data\Model;
99
use Atk4\Data\Persistence\Array_;
1010
use Atk4\Ui\App;
@@ -36,7 +36,7 @@ protected function init(): void
3636
}
3737
}
3838

39-
class ExecutorFactoryTest extends AtkPhpunit\TestCase
39+
class ExecutorFactoryTest extends TestCase
4040
{
4141
/** @var Model */
4242
public $model;

tests/ForFieldUiTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Data\Model;
99
use Atk4\Data\Persistence;
1010

@@ -24,7 +24,7 @@ protected function init(): void
2424
* Test is designed to verify that field which is explicitly editable should appear and be editable
2525
* even if 'never_persist' is set to true.
2626
*/
27-
class ForFieldUiTest extends AtkPhpunit\TestCase
27+
class ForFieldUiTest extends TestCase
2828
{
2929
/** @var Model */
3030
public $m;

tests/FormTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Data\Model;
99
use Atk4\Ui\App;
1010
use Atk4\Ui\Form;
1111

12-
class FormTest extends AtkPhpunit\TestCase
12+
class FormTest extends TestCase
1313
{
1414
/** @var Form */
1515
public $f;

tests/GridTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Atk4\Ui\Table;
88

9-
class GridTest extends \Atk4\Core\AtkPhpunit\TestCase
9+
class GridTest extends \Atk4\Core\Phpunit\TestCase
1010
{
1111
use Concerns\HandlesTable;
1212

tests/HtmlTemplateTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\Exception;
99
use Atk4\Ui\HtmlTemplate;
1010
use Atk4\Ui\HtmlTemplate\TagTree;
1111

12-
class HtmlTemplateTest extends AtkPhpunit\TestCase
12+
class HtmlTemplateTest extends TestCase
1313
{
1414
protected function assertSameTemplate(string $expectedTemplateStr, HtmlTemplate $template): void
1515
{

tests/JsIntegrationTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\Button;
99
use Atk4\Ui\View;
1010

11-
class JsIntegrationTest extends AtkPhpunit\TestCase
11+
class JsIntegrationTest extends TestCase
1212
{
1313
public function testIdIntegrity1(): void
1414
{

tests/JsTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\Jquery;
99
use Atk4\Ui\JsChain;
1010
use Atk4\Ui\JsExpression;
1111
use Atk4\Ui\JsFunction;
1212

13-
class JsTest extends AtkPhpunit\TestCase
13+
class JsTest extends TestCase
1414
{
1515
public function testBasicExpressions(): void
1616
{

tests/ListerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\Exception;
99
use Atk4\Ui\HtmlTemplate;
1010

11-
class ListerTest extends AtkPhpunit\TestCase
11+
class ListerTest extends TestCase
1212
{
1313
/**
1414
* @doesNotPerformAssertions

tests/LocaleTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\Exception;
99
use Atk4\Ui\Locale;
1010

11-
class LocaleTest extends AtkPhpunit\TestCase
11+
class LocaleTest extends TestCase
1212
{
1313
public function testException(): void
1414
{

tests/PaginatorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88

9-
class PaginatorTest extends AtkPhpunit\TestCase
9+
class PaginatorTest extends TestCase
1010
{
1111
public $p;
1212

tests/PostTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Data\Model;
99

10-
class PostTest extends AtkPhpunit\TestCase
10+
class PostTest extends TestCase
1111
{
1212
/** @var Model */
1313
public $model;

tests/RenderTreeTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\View;
99

1010
/**
1111
* Multiple tests to ensure that adding views through various patterns initializes them
1212
* nicely still.
1313
*/
14-
class RenderTreeTest extends AtkPhpunit\TestCase
14+
class RenderTreeTest extends TestCase
1515
{
1616
public function testBasic(): void
1717
{

tests/TableColumnColorRatingTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\Table;
99

10-
class TableColumnColorRatingTest extends AtkPhpunit\TestCase
10+
class TableColumnColorRatingTest extends TestCase
1111
{
1212
use Concerns\HandlesTable;
1313

tests/TableColumnLinkTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\Table;
99

10-
class TableColumnLinkTest extends AtkPhpunit\TestCase
10+
class TableColumnLinkTest extends TestCase
1111
{
1212
use Concerns\HandlesTable;
1313

tests/TableTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88

9-
class TableTest extends AtkPhpunit\TestCase
9+
class TableTest extends TestCase
1010
{
1111
/**
1212
* @doesNotPerformAssertions

tests/TagTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
7+
use Atk4\Core\Phpunit\TestCase;
88

9-
class TagTest extends AtkPhpunit\TestCase
9+
class TagTest extends TestCase
1010
{
1111
public function getApp()
1212
{

tests/ViewTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Atk4\Ui\Tests;
66

7-
use Atk4\Core\AtkPhpunit;
87
use Atk4\Core\Exception;
8+
use Atk4\Core\Phpunit\TestCase;
99

10-
class ViewTest extends AtkPhpunit\TestCase
10+
class ViewTest extends TestCase
1111
{
1212
/**
1313
* Test redering multiple times.

0 commit comments

Comments
 (0)