Skip to content

Commit e7c2d84

Browse files
committed
Make stress test configurable
1 parent 7891afc commit e7c2d84

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

phpunit.stress.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
beStrictAboutTodoAnnotatedTests="true"
1111
verbose="true"
1212
>
13+
<php>
14+
<env name="STRESS_MAX_MB" value="20" />
15+
<env name="STRESS_TAGS_M" value="1" />
16+
</php>
1317
<testsuites>
1418
<testsuite name="default">
1519
<directory suffix="Test.php">tests/Stress</directory>

tests/Stress/Memory/ReadWriteTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@
2020

2121
final class ReadWriteTest extends TestCase
2222
{
23-
const MAX_MEMORY_IN_MB = 25;
24-
2523
private string $file = '';
2624
private string $previousLimit = '';
2725

2826
protected function setUp(): void
2927
{
3028
$this->file = tempnam(sys_get_temp_dir(), 'xmlwriter');
3129
$this->previousLimit = ini_get('memory_limit');
32-
ini_set('memory_limit', self::MAX_MEMORY_IN_MB.'MB');
30+
ini_set('memory_limit', $_ENV['STRESS_MAX_MB'].'MB');
3331

3432
fwrite(STDOUT, 'Writing to file: '.$this->file.PHP_EOL);
3533
}
@@ -42,14 +40,20 @@ protected function tearDown(): void
4240

4341
public function test_it_can_handle_a_shitload_of_xml(): void
4442
{
43+
$maxMemoryMb = (int) $_ENV['STRESS_MAX_MB'];
44+
45+
fwrite(STDOUT, 'Running Read/Write stress test...'.PHP_EOL);
46+
fwrite(STDOUT, 'Number of tags: '.$_ENV['STRESS_TAGS_M'].'M'.PHP_EOL);
47+
fwrite(STDOUT, 'Max memory: '.$_ENV['STRESS_MAX_MB'].'MB'.PHP_EOL.PHP_EOL);
48+
4549
$size = $this->writeALot();
4650
fwrite(STDOUT, 'Written: '.$size.'MB'.PHP_EOL);
47-
static::assertGreaterThan(self::MAX_MEMORY_IN_MB, $size);
48-
static::assertLessThan(self::MAX_MEMORY_IN_MB, memory_get_peak_usage(true) / (1024**2));
51+
static::assertGreaterThan($maxMemoryMb, $size);
52+
static::assertLessThan($maxMemoryMb, memory_get_peak_usage(true) / (1024**2));
4953

5054
$numberOfFizzBuzzTags = $this->readALot();
5155
self::assertGreaterThan(50000, $numberOfFizzBuzzTags);
52-
static::assertLessThan(self::MAX_MEMORY_IN_MB, memory_get_peak_usage(true) / (1024**2));
56+
static::assertLessThan($maxMemoryMb, memory_get_peak_usage(true) / (1024**2));
5357
}
5458

5559
private function writeALot(): float
@@ -99,7 +103,7 @@ private function time(callable $run)
99103

100104
private function provideFizzBuzzTags(): Generator
101105
{
102-
$amount = (1024 ** 2);
106+
$amount = ((int) $_ENV['STRESS_TAGS_M']) * (1024 ** 2);
103107

104108
for ($i=1; $i<$amount; $i++) {
105109
yield match (true) {

0 commit comments

Comments
 (0)