@@ -41,4 +41,58 @@ public function testConsoleOutput(string $command, string $expectedOutput): void
4141 $ process ->getErrorOutput ()
4242 ));
4343 }
44+
45+ /**
46+ * @return Iterator<string, array{int, string[]}>
47+ */
48+ public static function provideParallelTimeouts (): Iterator
49+ {
50+ yield 'one timeout below the limit ' => [0 , [
51+ 'Child process timed out after 1 seconds ' ,
52+ 'Some parallel jobs have not finished, results for 1 of 1 files are missing ' ,
53+ ]];
54+
55+ yield '49 errors followed by a timeout reach the limit ' => [49 , [
56+ ...array_fill (0 , 49 , "Syntax error, unexpected ';' " ),
57+ 'Child process timed out after 1 seconds ' ,
58+ 'Reached system errors count limit of 50, exiting... ' ,
59+ 'Some parallel jobs have not finished, results for 1 of 50 files are missing ' ,
60+ ]];
61+ }
62+
63+ /**
64+ * @param string[] $expectedMessages
65+ */
66+ #[DataProvider('provideParallelTimeouts ' )]
67+ public function testParallelTimeoutReportsErrorLimitOnlyWhenReached (
68+ int $ previousErrorCount ,
69+ array $ expectedMessages
70+ ): void {
71+ $ filePaths = [];
72+ for ($ i = 5 ; $ i < 5 + $ previousErrorCount ; ++$ i ) {
73+ $ filePaths [] = __DIR__ . sprintf ('/../../e2e/parallel-system-errors-limit/src/File%02d.php ' , $ i );
74+ }
75+
76+ // The syntax-error files are larger, so the single worker processes them before the timeout file.
77+ $ filePaths [] = __DIR__ . '/Fixture/ParallelTimeout/Timeout.php ' ;
78+
79+ $ process = new Process ([
80+ PHP_BINARY ,
81+ 'bin/rector ' ,
82+ '--config ' ,
83+ __DIR__ . '/config/parallel-worker-timeout.php ' ,
84+ '--dry-run ' ,
85+ '--clear-cache ' ,
86+ '--no-progress-bar ' ,
87+ '--output-format=json ' ,
88+ ...$ filePaths ,
89+ ]);
90+ $ process ->setTimeout (20 );
91+ $ process ->run ();
92+
93+ $ this ->assertSame (1 , $ process ->getExitCode (), $ process ->getOutput () . $ process ->getErrorOutput ());
94+ $ result = json_decode ($ process ->getOutput (), true , flags: JSON_THROW_ON_ERROR );
95+ $ this ->assertSame (count ($ expectedMessages ), $ result ['totals ' ]['errors ' ]);
96+ $ this ->assertSame ($ expectedMessages , array_column ($ result ['errors ' ], 'message ' ));
97+ }
4498}
0 commit comments