Skip to content

Commit

Permalink
Merge pull request #8 from formal-php/fix-memory-assertion
Browse files Browse the repository at this point in the history
Fix memory assertion
  • Loading branch information
Baptouuuu authored Jul 14, 2024
2 parents a2b33b1 + ce34859 commit 6de6794
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
3 changes: 1 addition & 2 deletions blackbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

require 'vendor/autoload.php';

\ini_set('memory_limit', '-1');

use Innmind\BlackBox\{
Application,
Runner\Load,
Runner\CodeCoverage,
};

Application::new($argv)
->disableMemoryLimit()
->codeCoverage(
CodeCoverage::of(
__DIR__.'/src/',
Expand Down
20 changes: 11 additions & 9 deletions proofs/connection/pdo.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);
declare(ticks = 1);

use Formal\AccessLayer\{
Connection,
Expand Down Expand Up @@ -79,19 +80,20 @@ static function($assert) use ($connection) {

$select = Select::onDemand($table);
$rows = $connection($select);
$memory = \memory_get_peak_usage();

$count = $rows->reduce(
0,
static fn($count) => $count + 1,
);

$assert->same(100_000, $count);
// when lazy this takes a little less than 3Mo of memory
// when deferred this would take about 80Mo
$assert
->number(\memory_get_peak_usage() - $memory)
->lessThan(3_000_000);
->memory(static function() use ($assert, $rows) {
$count = $rows->reduce(
0,
static fn($count) => $count + 1,
);

$assert->same(100_000, $count);
})
->inLessThan()
->megaBytes(3);

$connection(DropTable::named($table));
},
Expand Down

0 comments on commit 6de6794

Please sign in to comment.