From c0caef15b3d9abff80550060757d5719abf9813f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 12 Dec 2023 12:32:28 +0100 Subject: [PATCH] Test slow test with runInSeparateProcess MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andreas Möller Co-authored-by: Michael Voříšek --- .../DefaultConfiguration/SleeperTest.php | 24 +++++++++++++++ .../Version10/DefaultConfiguration/test.phpt | 17 +++++++---- .../DefaultConfiguration/SleeperTest.php | 28 ++++++++++++++++++ .../Version8/DefaultConfiguration/test.phpt | 29 +++++++++++-------- .../DefaultConfiguration/SleeperTest.php | 28 ++++++++++++++++++ .../Version9/DefaultConfiguration/test.phpt | 29 +++++++++++-------- 6 files changed, 125 insertions(+), 30 deletions(-) diff --git a/test/EndToEnd/Version10/DefaultConfiguration/SleeperTest.php b/test/EndToEnd/Version10/DefaultConfiguration/SleeperTest.php index 98438218..caffe73d 100644 --- a/test/EndToEnd/Version10/DefaultConfiguration/SleeperTest.php +++ b/test/EndToEnd/Version10/DefaultConfiguration/SleeperTest.php @@ -359,4 +359,28 @@ public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): i ]; } } + + #[Framework\Attributes\RunInSeparateProcess] + public function testSleeperSleepsShorterThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void + { + $milliseconds = 50; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + #[Framework\Attributes\RunInSeparateProcess] + public function testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void + { + $milliseconds = 750; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } } diff --git a/test/EndToEnd/Version10/DefaultConfiguration/test.phpt b/test/EndToEnd/Version10/DefaultConfiguration/test.phpt index a149dea6..36584379 100644 --- a/test/EndToEnd/Version10/DefaultConfiguration/test.phpt +++ b/test/EndToEnd/Version10/DefaultConfiguration/test.phpt @@ -9,7 +9,12 @@ use PHPUnit\TextUI; $_SERVER['argv'][] = '--configuration=test/EndToEnd/Version10/DefaultConfiguration/phpunit.xml'; -require_once __DIR__ . '/../../../../vendor/autoload.php'; +/** + * @see https://github.com/sebastianbergmann/phpunit/blob/10.0.0/src/Framework/TestRunner.php#L288-L290 + */ +define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../../../vendor/autoload.php'); + +require_once PHPUNIT_COMPOSER_INSTALL; $application = new TextUI\Application(); @@ -21,9 +26,9 @@ Runtime: %s Configuration: %Stest/EndToEnd/Version10/DefaultConfiguration/phpunit.xml Random %seed: %s -..................... 21 / 21 (100%) +....................... 23 / 23 (100%) -Detected 11 tests that took longer than expected. +Detected 12 tests that took longer than expected. 1. 1.2%s (1.150) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAttributeWithValidMaximumDurationAndSlowThresholdAnnotation 2. 1.1%s (1.100) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAttribute @@ -34,10 +39,10 @@ Detected 11 tests that took longer than expected. 7. 0.9%s (0.800) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAnnotation 8. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidMaximumDurationAnnotation 9. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithUselessDocBlock -10. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDuration +10. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess -There is 1 additional slow test that is not listed here. +There are 2 additional slow tests that are not listed here. Time: %s, Memory: %s -OK (21 tests, 21 assertions) +OK (23 tests, 23 assertions) diff --git a/test/EndToEnd/Version8/DefaultConfiguration/SleeperTest.php b/test/EndToEnd/Version8/DefaultConfiguration/SleeperTest.php index db88730e..e48365ab 100644 --- a/test/EndToEnd/Version8/DefaultConfiguration/SleeperTest.php +++ b/test/EndToEnd/Version8/DefaultConfiguration/SleeperTest.php @@ -304,4 +304,32 @@ public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): i ]; } } + + /** + * @runInSeparateProcess + */ + public function testSleeperSleepsShorterThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void + { + $milliseconds = 50; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @runInSeparateProcess + */ + public function testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void + { + $milliseconds = 750; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } } diff --git a/test/EndToEnd/Version8/DefaultConfiguration/test.phpt b/test/EndToEnd/Version8/DefaultConfiguration/test.phpt index ea306909..07c6783b 100644 --- a/test/EndToEnd/Version8/DefaultConfiguration/test.phpt +++ b/test/EndToEnd/Version8/DefaultConfiguration/test.phpt @@ -9,7 +9,12 @@ use PHPUnit\TextUI; $_SERVER['argv'][] = '--configuration=test/EndToEnd/Version8/DefaultConfiguration/phpunit.xml'; -require_once __DIR__ . '/../../../../vendor/autoload.php'; +/** + * @see https://github.com/sebastianbergmann/phpunit/blob/8.5.19/src/Framework/TestCase.php#L754C1-L756 + */ +define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../../../vendor/autoload.php'); + +require_once PHPUNIT_COMPOSER_INSTALL; PHPUnit\TextUI\Command::main(); --EXPECTF-- @@ -19,23 +24,23 @@ Runtime: %s Configuration: %Stest/EndToEnd/Version8/DefaultConfiguration/phpunit.xml Random %seed: %s -................... 19 / 19 (100%) +..................... 21 / 21 (100%) -Detected 11 tests that took longer than expected. +Detected 12 tests that took longer than expected. 1. 1.2%s (1.000) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidSlowThresholdAndMaximumDurationAnnotation 2. 1.1%s (1.000) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAndSlowThresholdAnnotation 3. 1.1%s (0.900) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanSlowThresholdFromAnnotationWithValidSlowThresholdAnnotation - 4. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidSlowThresholdAnnotation - 5. 1.0%s (0.800) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAnnotation - 6. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidMaximumDurationAnnotation - 7. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithUselessDocBlock - 8. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDuration - 9. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #2 (600) -10. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #1 (550) + 4. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess + 5. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidSlowThresholdAnnotation + 6. 1.0%s (0.800) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAnnotation + 7. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidMaximumDurationAnnotation + 8. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithUselessDocBlock + 9. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDuration +10. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #2 (600) -There is 1 additional slow test that is not listed here. +There are 2 additional slow tests that are not listed here. Time: %s, Memory: %s -OK (19 tests, 19 assertions) +OK (21 tests, 21 assertions) diff --git a/test/EndToEnd/Version9/DefaultConfiguration/SleeperTest.php b/test/EndToEnd/Version9/DefaultConfiguration/SleeperTest.php index 1dcbc408..f3409c39 100644 --- a/test/EndToEnd/Version9/DefaultConfiguration/SleeperTest.php +++ b/test/EndToEnd/Version9/DefaultConfiguration/SleeperTest.php @@ -304,4 +304,32 @@ public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): i ]; } } + + /** + * @runInSeparateProcess + */ + public function testSleeperSleepsShorterThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void + { + $milliseconds = 50; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @runInSeparateProcess + */ + public function testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void + { + $milliseconds = 750; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } } diff --git a/test/EndToEnd/Version9/DefaultConfiguration/test.phpt b/test/EndToEnd/Version9/DefaultConfiguration/test.phpt index 7a07f1b9..77e532bb 100644 --- a/test/EndToEnd/Version9/DefaultConfiguration/test.phpt +++ b/test/EndToEnd/Version9/DefaultConfiguration/test.phpt @@ -9,7 +9,12 @@ use PHPUnit\TextUI; $_SERVER['argv'][] = '--configuration=test/EndToEnd/Version9/DefaultConfiguration/phpunit.xml'; -require_once __DIR__ . '/../../../../vendor/autoload.php'; +/** + * @see https://github.com/sebastianbergmann/phpunit/blob/9.4.3/src/Framework/TestCase.php#L799-L801 + */ +define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../../../vendor/autoload.php'); + +require_once PHPUNIT_COMPOSER_INSTALL; PHPUnit\TextUI\Command::main(); --EXPECTF-- @@ -19,23 +24,23 @@ Runtime: %s Configuration: %Stest/EndToEnd/Version9/DefaultConfiguration/phpunit.xml Random %seed: %s -................... 19 / 19 (100%) +..................... 21 / 21 (100%) -Detected 11 tests that took longer than expected. +Detected 12 tests that took longer than expected. 1. 1.2%s (1.000) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidSlowThresholdAndMaximumDurationAnnotation 2. 1.1%s (1.000) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAndSlowThresholdAnnotation 3. 1.1%s (0.900) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanSlowThresholdFromAnnotationWithValidSlowThresholdAnnotation - 4. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidSlowThresholdAnnotation - 5. 1.0%s (0.800) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAnnotation - 6. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidMaximumDurationAnnotation - 7. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithUselessDocBlock - 8. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDuration - 9. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #2 (600) -10. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #1 (550) + 4. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess + 5. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidSlowThresholdAnnotation + 6. 1.0%s (0.800) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAnnotation + 7. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidMaximumDurationAnnotation + 8. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithUselessDocBlock + 9. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDuration +10. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #2 (600) -There is 1 additional slow test that is not listed here. +There are 2 additional slow tests that are not listed here. Time: %s, Memory: %s -OK (19 tests, 19 assertions) +OK (21 tests, 21 assertions)