Skip to content

Commit

Permalink
qa: add failing test for laminas#5
Browse files Browse the repository at this point in the history
Thanks to Michael Weimann

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
  • Loading branch information
boesing committed Apr 28, 2021
1 parent db76f14 commit 90405f6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/unit/MemoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Laminas\Cache\Exception\OutOfSpaceException;

use function memory_get_usage;
use function mt_rand;
use function sha1;

/**
* @group Laminas_Cache
Expand Down Expand Up @@ -44,4 +46,21 @@ public function testThrowOutOfSpaceException()
$this->expectException(OutOfSpaceException::class);
$this->storage->addItem('test', 'test');
}

public function testReclaimMemory()
{
$this->options->setMemoryLimit(memory_get_usage(true) + 200);

try {
for ($i = 0; $i <= 100000; $i++) {
$this->storage->addItem('item' . $i, sha1((string) mt_rand()));
}

self::fail('filling the cache with test data to reach the memory limit failed');
} catch (OutOfSpaceException $ignore) {
}

$this->storage->flush();
$this->storage->addItem('item' . $i, sha1((string) mt_rand()));
}
}

0 comments on commit 90405f6

Please sign in to comment.