20
20
21
21
final class ReadWriteTest extends TestCase
22
22
{
23
- const MAX_MEMORY_IN_MB = 25 ;
24
-
25
23
private string $ file = '' ;
26
24
private string $ previousLimit = '' ;
27
25
28
26
protected function setUp (): void
29
27
{
30
28
$ this ->file = tempnam (sys_get_temp_dir (), 'xmlwriter ' );
31
29
$ 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 ' );
33
31
34
32
fwrite (STDOUT , 'Writing to file: ' .$ this ->file .PHP_EOL );
35
33
}
@@ -42,14 +40,20 @@ protected function tearDown(): void
42
40
43
41
public function test_it_can_handle_a_shitload_of_xml (): void
44
42
{
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
+
45
49
$ size = $ this ->writeALot ();
46
50
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 ));
49
53
50
54
$ numberOfFizzBuzzTags = $ this ->readALot ();
51
55
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 ));
53
57
}
54
58
55
59
private function writeALot (): float
@@ -99,7 +103,7 @@ private function time(callable $run)
99
103
100
104
private function provideFizzBuzzTags (): Generator
101
105
{
102
- $ amount = (1024 ** 2 );
106
+ $ amount = (( int ) $ _ENV [ ' STRESS_TAGS_M ' ]) * ( 1024 ** 2 );
103
107
104
108
for ($ i =1 ; $ i <$ amount ; $ i ++) {
105
109
yield match (true ) {
0 commit comments